简体   繁体   English

没有外键约束的Entity Framework 4相关表

[英]Entity Framework 4 relating tables with no foreign key constraint

I am working with Entity Framework for the first time. 我是第一次使用实体框架。 The database that I am working with has no foreign key constraints defined (and I cannot change that, integrity is controlled at the app level, out of my hands). 我正在使用的数据库没有定义外键约束(并且我无法更改它,完整性是在应用程序级别上完全由我自己控制的)。

There is a very strong convention in the database -- all PK's are named a specific way, and an FK field has exactly the same name as its corresponding PK. 数据库中有一个非常严格的约定-所有PK都以特定方式命名,并且FK字段与其对应的PK具有完全相同的名称。

When I draw a relation with EF, it seems to want to auto-create an FK field in the child table. 当我用EF绘制关系时,似乎想在子表中自动创建FK字段。 Is there any way I can teach EF to infer our relations based upon our convention? 我有什么方法可以教英孚根据我们的惯例推断我们的关系?

There is nothing built-in to infer FKs based on naming conventions, but you can manually add the associations to your model. 没有内置功能可以根据命名约定来推断 FK,但是您可以手动将关联添加到模型中。 Associations don't need an underlying FK constraint so you can add the associations to the model only... 关联不需要底层的FK约束,因此您只能将关联添加到模型中...


Update: In the latest version of the Model Comparer for EF4 , I added a feature for inferring FKs and generating associations in EFv4 models based on inferred FK constraints. 更新:在最新版本的EF4模型比较器中 ,我添加了一项功能,用于基于FK推断的条件推断FK并在EFv4模型中生成关联。 Blogged about it here: http://huagati.blogspot.com/2010/12/inferring-foreign-key-constraints-in.html 在此处发布博客: http//huagati.blogspot.com/2010/12/inferring-foreign-key-constraints-in.html

I hope that helps... 希望对您有帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM