ef4 map model defined function to property
I've seen model defined functions used in in-code queries (queries written by the developer using Linq etc) and I'm wondering if there's any way to map a model-defined function to an entity property so that EF4 will automatically query the database using it.
For example:
Suppose I have a Product
class and an Order
class and that Product
has a TotalSold
property. Ideally I would like to create a model defined function like:
select sum(o.quantity) from order, product where o.productid = product.productid
and bind that to the TotalSold
property of Product
so that every query for a given Product
would auto gen开发者_如何学Goerate an inner select that would populate the TotalSold
property.
Does this make sense? Is it possible?
I found a good-enough solution and blogged about it at http://statichippo.com/archive/2011/01/26/Mapping-a-computed-property-in-EF4.aspx
精彩评论