OrmLite SelectFilter use with SelectMulti

Hi guys,

I am attempting to use the new SelectFilter as a blanket approach, with the following code in my AppHost.Configure:

        OrmLiteConfig.SqlExpressionSelectFilter = q =>
        {
            if (q.ModelDef.ModelType.HasInterface(typeof(IBaseType)))
            {
                q.Where<IBaseType>(x => x.ValidTo == null);
            }
        };

This works fine for Selects but when my code hits:

       var results = dbConn.SelectMulti<T, T2>(expression);

       (where T : IBaseType where T2 : IBaseType

       public interface IBaseType
       {
        ....
        DateTime? ValidTo { get; set; }
        ....
        }
       )

I get an error as follows:

Additional information: SQL logic error or missing database
no such column: IBaseType.ValidTo

If I set up the SelectFilters like the following it all works:

         SqlExpression<SettlementTerm>.SelectFilter = q => q.Where(x => x.ValidTo == null);
         SqlExpression<LinkSupplierToSettlementTerm>.SelectFilter = q => q.Where(x => x.ValidTo == null);

I am looking for a solution to get the blanket approach working so that the filter applies automatically to every call.

Forgive me if my formatting is incorrect, first post!

Thanks
Simon

Normally all queries on an SqlExpression API needs to be the table that’s queried so OrmLite has access to the table metadata, however in this case the expected behavior when using an Interface would be not to prefix the query with the table name which should be resolved from the latest v4.5.11 release that’s now available on MyGet.

So your first config should now work, i.e:

OrmLiteConfig.SqlExpressionSelectFilter = q =>
{
    if (q.ModelDef.ModelType.HasInterface(typeof(IBaseType)))
    {
        q.Where<IBaseType>(x => x.ValidTo == null);
    }
};

Have updated and now getting error:

“ambiguous column name: ValidTo”

Thanks

That’s the result of removing the Table prefix, you’re executing this on a query that has multiple ValidTo columns for which ValidTo IS NULL SQL Fragment is now ambiguous so removing the table prefix wont work if you’re joining multiple tables with the same ValidTo column name.

The best we can do is change it so if the Interface matches the base Table in SqlExpression<Table> then we’ll apply the condition to the base table. That’s all we can do to support conditions on interfaces which are not normally supported.

This change is now available from the official v4.5.12 fix release that’s now published on NuGet.