使用相同的键与不同的tablas进行关系 [英] Doing Relations with the same key to different tablas

查看:78
本文介绍了使用相同的键与不同的tablas进行关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,这是我的问题:

我有两个表亲属(IDRelative为Key,Name等)和Residents(IDResident为密钥,IDSignal,IDTypeSignal等)

>我想建立一个关系IDResident - > IDSignal或IDRelative - > IDSignal是IDTypeSignal值的函数。

如果IDTypeSignal = 1则关系将是IDResident - > IDSignal

如果IDTypeSignal = 2那么关系将是IDRelative - > IDSignal

如果IDTypeSignal = -1则没有关系。


我想用EntityFramework建模这种关系,但我不确定如果这种关系可以做到。


有可能建模吗?

谢谢。

Hello, here is my question:

I have two tables Relatives (with IDRelative as Key,Name etc) and Residents (with IDResident as key, IDSignal, IDTypeSignal and so on)

I want to make a relation IDResident --> IDSignal or IDRelative --> IDSignal in function of the value of IDTypeSignal.

If IDTypeSignal = 1 then the relation will be IDResident --> IDSignal

If IDTypeSignal = 2 then the relation will be IDRelative --> IDSignal

If IDTypeSignal = -1 then there is no relation.


I want to model this relations with EntityFramework but I´m not sure If this kind of Relations are possible to do.


Is that possible to model?

Thank you.

推荐答案

它不是由于EF还不支持关联条件,因此无法直接对此进行建模。你最好的选择是创建一组视图来突出关联结束,例如: IDTypeSignal = 1的视图,另一个视图为2.您可以创建两个关联并将它们映射到这些视图。之后,您需要使用存储过程来更新关联的插入和删除行为。

请注意,设计者此时不支持此方法,因为它不会将映射关联公开给sprocs。您需要编辑XML。

另一种方法是公开IDTypeSignal和IDsignal属性以及"层叠"。他们是适当的关联式.NET构造。不太干净,但实施起来要简单得多。
It isn't possible to directly model this since the EF does not yet support conditions on associations. Your best bet woudl be to create a set of views which project out the association ends, e.g. a view for IDTypeSignal=1, and another for 2. You could then create two associations and map them to these views. After that, you'd need to use stored procedures to update the associations' insert and delete behaviors.

Note that the designer does not support this approach at this time since it does not expose mapping associations to sprocs. You'll need to go edit the XML.

Another approach is to just expose the IDTypeSignal and IDsignal properties and "layer over" them the appropriate association-like .NET constructs. Not quite as clean, but much simpler to implement.


这篇关于使用相同的键与不同的tablas进行关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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