【发布时间】:2019-04-05 13:52:47
【问题描述】:
我正在做一个项目。当我第一次开始时,我有一个订单模型和地址模型。但是,现在我想将 Order 模型更改为具有 AddressTo 和 AddressFrom 而不仅仅是 Address。
地址型号:
public class Address
{
public int AddressId { get; set; }
public int ZipCodeId { get; set; }
public string Street { get; set; }
public int Nr { get; set; }
public virtual ICollection<Order> Order { get; set; }
public virtual ZipCode ZipCode { get; set; }
}
订购型号:
public class Order
{
public int OrderId { get; set; }
public int CustomerId { get; set; }
public virtual Address Address { get; set; }
public DateTime OrderDate { get; set; }
public DateTime SentDate { get; set; }
public string Title { get; set; }
public string Type { get; set; }
public string Content { get; set; }
public int ExpectedHours { get; set; }
public int AmountWorkers { get; set; }
public virtual Customer Customer{ get; set; }
}
我想要的顺序:
public class Order
{
public int OrderId { get; set; }
public int CustomerId { get; set; }
public virtual Address AddressTo { get; set; }
public virtual Address AddressFrom { get; set; }
public DateTime OrderDate { get; set; }
public DateTime SentDate { get; set; }
public string Title { get; set; }
public string Type { get; set; }
public string Content { get; set; }
public int ExpectedHours { get; set; }
public int AmountWorkers { get; set; }
public virtual Customer Customer{ get; set; }
}
我意识到没有FluentApi 解决这个问题是不可能的。但是,我发现很难克服这个问题。
我想要的是数据库中的 Order 表显示 ID 列 AddressToId 和 AddressFromId,而不仅仅是 AddressId(现在就是这样)。
非常感谢社区在这方面的帮助。
【问题讨论】:
标签: c# entity-framework-core one-to-many ef-fluent-api