Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 实体框架中与单个表相关的多个表的映射关系_Entity Framework_Database Design - Fatal编程技术网

Entity framework 实体框架中与单个表相关的多个表的映射关系

Entity framework 实体框架中与单个表相关的多个表的映射关系,entity-framework,database-design,Entity Framework,Database Design,我有一个表,其中包含各种对象/实体的用户权限,如下所示: object_type //an enum referring the the type of object that this record applies to object_id //the id of the object user_id can_edit etc. 这将与我的项目中其他几个没有任何共同点的表相关(照片就是一个例子)。要获取对象的权限,我希望能够执行以下操作: //get the first photo alon

我有一个表,其中包含各种对象/实体的用户权限,如下所示:

object_type //an enum referring the the type of object that this record applies to
object_id //the id of the object
user_id
can_edit
etc.
这将与我的项目中其他几个没有任何共同点的表相关(照片就是一个例子)。要获取对象的权限,我希望能够执行以下操作:

//get the first photo along with all of the user permissions related to it
context.Set<Photos>()
     .Include(p=>p.UserPermissions)
     .FirstOrDefault(p=>p.Id == 1)  
//获取第一张照片以及与之相关的所有用户权限
context.Set()
.Include(p=>p.UserPermissions)
.FirstOrDefault(p=>p.Id==1)

如果需要的话,我可以重新构造数据库,所以我想在这里介绍一下您认为最好的解决方案。

我建议它们确实有一些共同点。它们都是可以控制权限的资源。在此上下文中,“资源”是“照片”等的泛化。或者,用对象类表示,照片是资源的一个子类


在这种情况下,我建议你的问题可能已经得到了回答。这是Bill Karwin的回答,描述了几种针对继承类型情况进行设计的方法。它赢得了很多选票。

我建议他们确实都有共同之处。它们都是可以控制权限的资源。在此上下文中,“资源”是“照片”等的泛化。或者,用对象类表示,照片是资源的一个子类


在这种情况下,我建议你的问题可能已经得到了回答。这是Bill Karwin的回答,描述了几种针对继承类型情况进行设计的方法。它赢得了很多选票。

使用支持行安全性的数据库要比使用支持行安全性的数据库聪明100倍左右