非实体密钥上的实体之间的关联 [英] Association Between Entities on Non Entity Keys

查看:80
本文介绍了非实体密钥上的实体之间的关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个遗留数据库模式(由于内部压力无法更改),它没有定义任何外键关系,这些关系在当前应用程序代码中维护。

我们希望将我们的应用程序移动到我们的应用程序中使用Entity Framework,并通过设计器手动创建关联。对于少数实体,它们之间的关系实际上并未在其实体/主键上定义。例如:

TableA具有主键AID(int)和列DKEY(nchar),Name(nchar)。
TableB有主键BID(int)和列ADKEY(nchar)。
在TableA.DKEY = TableB.ADKEY上将TableA连接到TableB的应用程序代码中存在关系

我不确定如何在实体框架内制定此关联(或者如果它当前受支持) 。由于这些类型是关联在我们的应用程序中使用,我想知道是否有人有任何关于如何进行的想法。


谢谢,

David

We have a legacy database schema (due to internal pressures can not be changed) that does not define any foreign key relationships, these relationships are maintained within the current application code.

We are looking to move our application to use the Entity Framework for our application and are creating the associations manually through the designer. For a few entities, the relationships between them are not actually defined on their entity/primary keys. For example:

TableA has primary key AID(int) and columns DKEY(nchar), Name (nchar).
TableB has primary key BID (int) and column ADKEY (nchar).
A relationship exists in the application code that joins TableA to TableB on TableA.DKEY = TableB.ADKEY

I am not sure how to formulate this association (or if it is currently supported) within the Entity Framework. As these types are association are used throughout our application, I would like to know if anyone has any ideas about how to proceed.


Thanks,

David

推荐答案

Hi *,

您可以在模型中定义关联,即使它们在数据库中不存在。只需从实体中删除类似FK的属性,添加关联和映射。就这样。其余的将在EF完成。无论如何,缺少真正的FK约束都会导致DB中的某些数据不完整(不仅来自EF程序)。
Hi *,

you can define associations in model even if they don't exist in database. Just delete the FK-like property from entity, add association and map. That's all. The rest will be done in EF. Anyway lack of real FK constraints can cause some data incosistency in DB (not only from EF program).


这篇关于非实体密钥上的实体之间的关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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