使用实体框架具有复杂过滤条件的导航属性
我使用 Entity Framework 4 将遗留应用程序迁移到 C#。数据模型由两个表组成,“约会”和“授权”,它们是一对多关系。在概念模型中,类得到了正确的表示。此外,导航属性“Appointment.Authorizations”到目前为止工作正常。
但我希望导航属性“Appointment.Authorizations”仅列出满足特定条件的 Authorization 类对象。标准可能非常复杂。用SQL表达的话,大约有30行代码。查询中还涉及到其他几个表。
目前哪种方法最适合更改导航属性的行为,以便仅显示所需的选择列出?只读集合就可以了。
I use the Entity Framework 4 to migrate a legacy application to C #. The data model consists of two tables, "Appointment" and "Authorization", which are in a one to many relationship. In the conceptual model, the classes are properly represented. Also the navigation property "Appointment.Authorizations" works so far correct.
But I want the navigation property "Appointment.Authorizations" only objects of class Authorization are listed that meet certain criteria. The criteria can be very complex. Expressed in SQL, there are about 30 lines of code. Several other tables are also involved in the query.
Which method is best for now to change the behavior of the navigation property, so that only the desired selection is listed? A read only Collection would be ok.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导航属性看起来不错,您所描述的是业务逻辑,使其远离 SQL 和 C#,您可以在其中针对此逻辑编写单元测试。
如果您可以提供有关“选择”逻辑的更多信息并提供一些代码,我们可以帮助您找到正确的方向。
The navigation property looks okay, what your describing is business logic keep it out of the SQL and in the C#, where you can write unit tests against this logic.
If you can provide more information about the "select" logic and provide some code we can help you get in the right direction.