NHibernate's formula functionality in Entity Framework Code First?
I'm searching for the formula functionality in NHibernate with EF Code first.
Say that I have an Order with OrderLines, on the order I have my TotalAmount which could look like this
public decimal OrderTotal { return orderLines.Sum(x => x.Price); }
But I want this property to be searchable in Entity Framework so I want to do some sql code that will do this but in Sql. The result from the sql will not be set or read just be used in the search, in the memory the .net code w开发者_高级运维ill be used.
How can I accomplish this?
EF code first doesn't have any such functionality. Even big EF is not able to do this directly as you described - you must have separate computed property in entity and model defined function for querying in EDMX (I think this should be doable in model defined function). Obviously code first doesn't have EDMX and because of that it can't define model defined function (no code fist alternative exists as I know - actually no code first alternative exists for many advanced features of EDMX like conditional mapping, query view, defining query, model defined function, function import and stored procedure mapping).
精彩评论