实体框架4.1:一种非常特殊的关系

发布于 2024-12-19 15:14:12 字数 764 浏览 1 评论 0原文

我的数据库中有一个表(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不放开 2024-12-26 15:14:12

如果我正确理解您的问题,则无法在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文