ef mysql 外键 一对一_mysql-AspNet EF将外键引用到字段

我有两个模型:

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,这不是我想要的…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值