ef4 将模型定义的函数映射到属性
我已经看到在代码内查询(开发人员使用 Linq 等编写的查询)中使用模型定义的函数,我想知道是否有任何方法可以将模型定义的函数映射到实体属性,以便 EF4 会自动查询使用它的数据库。
例如:
假设我有一个 Product
类和一个 Order
类,并且 Product
有一个 TotalSold
属性。理想情况下,我想创建一个模型定义的函数,例如:
select sum(o.quantity) from order, Product where o.productid = Product.productid
并将其绑定到TotalSold
Product
的属性,以便给定 Product
的每个查询都会自动生成一个内部选择,该内部选择将填充 TotalSold
属性。
这有道理吗?是否可以?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个足够好的解决方案,并在博客中介绍了它 http://statichippo.com/archive/2011/01/26/Mapping-a-compulated-property-in-EF4.aspx
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