problem is this, i have a property in entity:
public bool Expired
{
get { return CreationDate.AddDays(30) < DateTime.UtcNow; }
}
And of course I can not use it in entity framework queries, although it does not contain anything, that EF could not handle, it is just that it does not even try.
Question would be, is it possible to keep such mini queries as properties somehow in entity (for example using Func<T, bool>) for reusing in forming more complex queries, like
Products.Where(x.Expired || x.Price > something)
UPDATE:
Oh, after posting question, I tried several more queries on google and found this:
http://damieng.com/blog/2009/06/24/client-side-properties-and-any-remote-linq-provider
It requires some additional code, so I wrote CompiledExpression using mentioned library like this for my property:
private static readonly CompiledExpression<GuaranteeTransaction, bool> ShouldBeExpiredExpression =
DefaultTranslationOf<GuaranteeTransaction>
.Property(x => x.ShouldBeExpired)
.Is(x => x.CreationDate < DateTime.UtcNow.AddDays(-30));
And it turns out AddDays also is not supported by entity framework. I think I could create another CompiledExpression to replace DateTime.UtcNow.AddDays(-30) to property using same mechanism, but that would be ridiculous (in terms of readability and complexity).
As long as I did not received any better answer, I kept things simple: moved reusable expressions to repository. It may not look so clean and may be is not in the best place, but they’re doing their job and no additional complexity is brought in, so I guess it is quite nice solution.