简体   繁体   English

EF4通用实体ID

[英]EF4 Generic Entity ID

I have an address table that is like as follows: 我有一个地址表,如下所示:

Address 地址

  • int address_id int address_id
  • string street1 弦街1
  • string street2 弦街2
  • ... other address fields ... ...其他地址字段...
  • int entity_id 整数entity_id
  • int entity_type_id 整数entity_type_id
  • datetime created_at 日期时间created_at
  • datetime updated_at 日期时间updated_at
  • datetime deleted_at 日期时间delete_at

The intention is to allow other entities (like person, supplier, office, etc). 目的是允许其他实体(例如个人,供应商,办公室等)。

My problem is that I cannot foreign key the entity_id to the tables that represent the other entities and therefore I am at lost as how how I can use entity framework to have associations / navigation properties. 我的问题是我无法将entity_id外键到代表其他实体的表中,因此我不知道如何使用实体框架具有关联/导航属性。

I think i could put a entity table in the system and have every other entity derive from this but I am not sure this would not cause unnessecary difficulties later on. 我认为我可以在系统中放置一个实体表,并让其他所有实体派生自该表,但是我不确定此后是否会引起不必要的困难。

Can anyone suggest an option? 谁能建议一个选择?

You cannot do that with current EF version. 您无法使用当前的EF版本执行此操作。 EF uses same rules like FK relation in database so if you cannot make it in database you also cannot make it in EF. EF在数据库中使用与FK关系相同的规则,因此,如果无法在数据库中建立关系,则也无法在EF中建立关系。 You will not have navigation property but you can still use manual join in Linq-to-entities query. 您将没有导航属性,但仍可以在Linq-to-entities查询中使用手动联接。

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

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