我有两个模型:
public class Customer
{
public int Id { get; set; }
public int Number { get; set; }
public int ParentNumber { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string Language { get; set; }
}
和
public class Batch
{
public int Id { get; set; }
public int Number { get; set; }
public string FileName { get; set; }
public string ArticleNumber { get; set; }
public string ArticleDescription { get; set; }
public int Weight { get; set; }
public DateTime ProductionDate { get; set; }
public DateTime DeliveryDate { get; set; }
public DateTime BestBeforeDate { get; set; }
public DateTime? ApprovedDateTime { get; set; }
public int CustomerId { get; set; }
public virtual Customer Customer { get; set; }
}
一批可以拥有一个客户.但是,由于我们要从另一个系统导入数据,因此我们决定不接管其ID.
现在,外键显示尝试通过属性Customer.Id查找客户.
我试图实现从Batch.Customer(Id)获取外键指向Customer.Number
我将如何成功做到这一点?
我尝试通过将Customer.Number定义为具有Key属性的键..但这使主键从Id转到Number,这不是我想要的…