Entity Framework Code First 中的 NHibernate 公式功能?
我首先在 NHibernate 中使用 EF 代码搜索公式功能。
假设我有一个带有 OrderLines 的订单,在订单上我有我的 TotalAmount,它可能看起来像这样,
public decimal OrderTotal { return orderLines.Sum(x => x.Price); }
但我希望这个属性可以在实体框架中搜索,所以我想做一些 sql 代码来执行此操作,但在 Sql 中。 sql 的结果不会被设置或读取,只会在搜索中使用,在内存中将使用 .net 代码。
我怎样才能做到这一点?
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 will be used.
How can I accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EF code first 没有任何此类功能。即使大型 EF 也无法按照您所描述的那样直接执行此操作 - 您必须在实体中具有单独的计算属性,并且 用于在 EDMX 中查询的模型定义函数(我认为这应该在模型定义函数中可行)。显然,代码优先没有 EDMX,因此它无法定义模型定义的函数(据我所知,不存在代码优先替代方案 - 实际上,对于 EDMX 的许多高级功能,如条件映射、查询视图、定义,不存在代码优先替代方案)查询、模型定义函数、函数导入和存储过程映射)。
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).