asbestossupply
asbestossupply

Reputation: 11919

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 generate an inner select that would populate the TotalSold property.

Does this make sense? Is it possible?

Upvotes: 2

Views: 250

Answers (1)

asbestossupply
asbestossupply

Reputation: 11919

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

Upvotes: 1

Related Questions