加入各种关系多样性表 [英] Join table for all kinds of relationship multiplicity

查看:107
本文介绍了加入各种关系多样性表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个企业数据库,实体之间的所有关系都通过一个连接表进行。为简单起见,假设我们在表B中有一个带有Base抽象类的TPT方案,在表C,U,S中有派生类C,U和S.还有一个连接表R保存所有关系。

C和U之间的关系是多对一的(计算机有主用户。同一用户可以是多台计算机的主用户)。 C和S之间的关系是多对多的(比如计算机安装了软件)。

表R有其他字段,因此EF不会将其视为连接表。为了使它看起来像是C - > U关系的连接表,我在SSDL中使用了一个DefiningQuery来映射到C-> U关系。我遇到的问题是,除非我将C - > U关系的两端的多重性定义为"*"。 (即将其建模为多个),我在运行时得到的错误类似于

SM.msl(30,6):错误3003:从第30行开始映射片段的问题:给定基数的基数关联End Member Computer,它应该映射到表ComputerPrimaryUserQuery的键列。修复映射或更改此结束的多重性。

有没有解决方案?我讨厌把基数= *因为它给生成的类带来了错误的印象。

谢谢,
Darshat


Darshat Shah -Senior开发人员,System Center服务管理器团队

Hi,
We have an enterprise database where all relationships between entities go via a single join table. For simplicity, say we have a TPT scheme with Base abstract class in table B and derived classes C, U, and S in tables C, U, S. There is also a single join table R that holds all the relationships.

The relationship between C and U is many-to-one (computer has a primary user. Same user can be primary user for multiple computers). The relationship between C and S is many-to-many (say computer has installed software).

The table R has other fields so EF will not see it as a join table. In order to make it appear like a join table for the C-->U relationship, I used a DefiningQuery for the EntitySet in SSDL that maps to C->U relationship. The problem I'm running into is that, unless I define the multiplicity of both ends of the C-->U relationship to be "*" (i.e. model it as many-many), I get errors at runtime similar to

SM.msl(30,6) : error 3003: Problem in mapping fragments starting at line 30:Given the cardinality of Association End Member Computer, it should be mapped to key columns of the table ComputerPrimaryUserQuery. Either fix the mapping or change the multiplicity of this end.

Is there any solution to this? I'd hate to put the cardinality=* because it gives the wrong impression programming against the generated classes.

Thanks,
Darshat


Darshat Shah -Senior Developer, System Center Service Manager Team

推荐答案

模块创建将表与连接表连接在一起的视图,我不相信有一个演练。但是,您可以做的一件事是删除"不正确"的导航属性。如果这很好地符合您的编程模型,或者至少将其声明为私有...
Modulo creating views that join together the tables with the join table, I do not believe that there is a walkthrough. But, one thing you could do is remove the navigation property on the "incorrect" many end, if that matches your programming model well, or at least declare it as private...


这篇关于加入各种关系多样性表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆