The problem is this, I have a property in essence:
public bool Expired { get { return CreationDate.AddDays(30) < DateTime.UtcNow; } }
And, of course, I canβt use it in requests for entity infrastructure, although it does not contain anything that EF could not handle, it just doesnβt even try.
Question: is it possible to save such mini-queries as properties in any way in the entity (for example, using Func<T, bool> ) for reuse in the formation of more complex queries, for example
Products.Where(x.Expired || x.Price > something)
UPDATE: Oh, after posting the question, I tried a few more queries on google and found this:
http://damieng.com/blog/2009/06/24/client-side-properties-and-any-remote-linq-provider
This requires some additional code, so I wrote CompiledExpression using the specified 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 that AddDays is also not supported by entity infrastructure. I think I could create another CompiledExpression to replace DateTime.UtcNow.AddDays (-30) with a property using the same mechanism, but that would be funny (in terms of readability and complexity).