实体框架4.1:一种非常特殊的关系
我的数据库中有一个表(AccessControl),它描述了表客户和其他表中包含的信息的一种用户“访问控制列表”。
示例:实体 CUSTOMER 由 EntityId #1 标记。如果用户属于部门#6,他可以访问客户#16和#31的记录,但他不能访问#14,部门#3中的用户可以查看:
Table ACCESSCONTROL:
EntityId PrimaryKey DepartmentId
1 16 6
1 31 6
1 14 3
这里是我所在的类的示例在域中使用:
Public Class Customer
Public Property Id As Integer
.......
Public Overridable Property Acl As ICollection(Of AccessControl)
End Class
Public Class AccessControl
Public Property EntityId As Integer
Public Property PrimaryKey As Integer
Public Property DepartmentId As Integer
End Class
如何使用流畅的 Code First 方法将这种关系描述到 DbContext 定义中? 先感谢您。
I have in my database a table (AccessControl) that describes a sort of users "access control list" for the informations contained in the table Customers and other tables.
Example: the entity CUSTOMER is marked by the EntityId #1. If a user belongs to the department #6, he can access the records of customer #16 and #31, but he can't for #14, that can viewed by user in department #3:
Table ACCESSCONTROL:
EntityId PrimaryKey DepartmentId
1 16 6
1 31 6
1 14 3
Here an example of the classes I am using in the domain:
Public Class Customer
Public Property Id As Integer
.......
Public Overridable Property Acl As ICollection(Of AccessControl)
End Class
Public Class AccessControl
Public Property EntityId As Integer
Public Property PrimaryKey As Integer
Public Property DepartmentId As Integer
End Class
How can I describe this relationship into the DbContext definition using a fluent Code First approach?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您的问题,则无法在 EF 中设置此关系。它不起作用的原因有很多,但基本原因是:除非您能够在 DB 中设置此关系,否则您也不能在 EF 中设置它。您的关系是数据驱动的,并且 EF 对数据驱动映射的支持非常有限 - 例如 TPH 继承在您的场景中不起作用。
If I understand your problem correctly it is not possible to setup this relation in EF. There are many reasons why it will not work but the base is: unless you are able to set this relation in DB you cannot set it in EF as well. Your relation is data driven and EF has very limited support for data driven mapping - for example TPH inheritance which will not work in your scenario.