[英]How do I map one entity to many entities in Entity Framework?
I have 4 entities. 我有4个实体。 They look something like this:
他们看起来像这样:
public abstract class Entity
{
public Guid Id { get; set; }
public DateTime CreationDate { get; set; }
}
public class Client :
Entity
{
public string Name { get; set; }
// ...
public IList<Note> Notes { get; set; }
}
public class Supplier :
Entity
{
public string Name { get; set; }
// ...
public IList<Note> Notes { get; set; }
}
public class Note :
Entity
{
public Guid EntityId { get; set; } // This points to the Id field of a Client or Supplier
public virtual Entity Entity { get; set; }
public string EntityName { get; set; } // "Client", "Supplier", etc.
}
Now, what I want is for this to create 3 tables, Client, Supplier, and Note. 现在,我要为此创建3个表,即Client,Supplier和Note。 The note table needs to point to the client and supplier note on the EntityId field.
注释表需要指向EntityId字段上的客户和供应商注释。 What is actually happening, is that EF is adding Client_ID and Supplier_ID fields to the Note table, with foreign keys to each respective table.
实际发生的情况是,EF将“ Client_ID”和“ Supplier_ID”字段添加到“注释”表中,并对每个表添加了外键。 The effect of this is basically that notes can only be created if both client and supplier are included.
基本上,这样做的效果是,只有同时包含客户和供应商,才能创建便笺。
What do I need to do to make this behave the way I need? 我需要怎么做才能使其表现出所需的方式?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.