2

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?

hackerhasid
  • 11,699
  • 10
  • 42
  • 60

1 Answers1

1

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

hackerhasid
  • 11,699
  • 10
  • 42
  • 60
  • Nice job. I was hoping that the work discussed in http://blogs.msdn.com/b/efdesign/archive/2009/01/07/model-defined-functions.aspx would have been made production quality in EF 4 or 4.1. I'm going to keep looking for something that says it is ... – John Kaster Jun 03 '11 at 03:31