在实体框架同桌关系 [英] Same table relationship in Entity Framework

查看:100
本文介绍了在实体框架同桌关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能有一个关联映射表本身?

Is it possible to have an association mapping a table to itself?

例如。

Table:  
ConditionId  
ConditionName 
... 
...  
ParentConditionId

在这里我们可以有很多ParentConditionIds每个映射到同一个ConditionId。

where we can have many ParentConditionIds each mapping to the same ConditionId.

我已经尝试了一对多映射,但时有没有孩子,我得到一个错误。

I've tried a one to many mapping but I'm getting an error when there is no children.

推荐答案

是的,它是可能的。把FK在数据库中,向导会正确映射它。确保ParentConditionId为空。

Yes it is possible. Put the FK in your database and the wizard will map it correctly. Make sure ParentConditionId is nullable.

这篇关于在实体框架同桌关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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