I know this is probably more my lack of knowledge of dotnet than something about OrmLite, but I have a number of table based operations that I’d like to abstract and they look something like this:
var cntSomethingFortheDay = Db.Scalar<SomeClass, int>(x => Sql.Count(x.SomeProperty), x => x.SomeDate >= DateTime.Now.AddDays(-1) && x.SomeDate <= DateTime.Now);
I know how to use generics to pass in an arbitrary “SomeClass”, but is it possible to pass in “SomeProperty” and “SomeDate” as well? (In this case, different classes have different date properties. I’d prefer not to implement interfaces if not necessary). As an alternative, I could also pass in the filter expression itself, but I do know how to craft a stand alone expression outside of the orm lite methods.
It would require manually building up the same Expression tree that the compiler would’ve generated which can be difficult to do dynamically and very fragile if you get anything wrong, e.g. using wrong type or cast.
If typed static expressions are ok, you can extract the filter into a variable that you can pass in as an argument, eg: