2009-02-14 119 views
0

我想我不太确定Linq继承应该如何工作。Linq to SQL继承问题

我有一个“用户”实体,我想从“用户”实体继承另外两个名为“Creator”和“Assigned”的实体(基本上它们应该与用户实体具有相同的确切属性)我不需要任何额外的属性。我可以在设计师中做到这一点。

问题是,当我尝试将继承的实体与另一个实体关联时 - 我无法访问基础实体中的任何属性。我不应该访问那些绑定到其他实体吗?在我看来,我应该如此。

回答

0

这听起来更像是一种关系而不是对我的继承。也就是说,所有的实体都是用户,但有些用户与其他用户有创建者关系,有些用户具有指定的关系。建立这个模型最简单的方法可能是为创作者创建一个连接表,为受让者创建另一个连接表。从连接表中的两列创建外键关系回到用户表。将所有这些表格拖放到设计器表面时,每个用户都将获得createdBy/created和assignee /分配给实体集合。我假设,你的数据库约束将限制它,以便每个用户只有一个创建者,并且一个用户没有被分配给多个其他用户(或者根据你的规则可能不是)。

user table 
user_id int identity not null primary key 
user_name varchar 
.... 

created_by 
created_by_id int identity not null primary key 
creator int not null, FK to user.user_id 
createe int not null, FK to user.user_id 
(with a unique index on creator/createe -- or both could be the PK) 
(constraint creator <> createe) 

assigned_to 
assigned_to_id int identity not null primary key 
owner_id int not null, FK to user.user_id 
assignee_id int not null, FK to user.user_id 
(with a unique index on assignee_id -- or not) 
(constraint owner_id <> assignee_id -- or not)