当前位置: 移动技术网 > IT编程>开发语言>.net > .netcore2.1 ef 使用外键关联查询

.netcore2.1 ef 使用外键关联查询

2019年10月10日  | 移动技术网IT编程  | 我要评论

外科风云 小说,陈德荣天津市委常委,考试吧会计

 
  //实体类
[table("invoiceinfo", schema = "obs")] public class invoice { [key] public string invoice_num { get; set; } public string merchant_id { get; set; } public datetimeoffset? verify_time { get; set; } //one to many
public virtual ilist<invoice_relation> invoice_file_list { get; set; }   //one to one public virtual business invoice_business { get; set; } }
//数据库  postgredbcontext相关配置

protected override void onmodelcreating(modelbuilder builder) { base.onmodelcreating(builder); builder.entity<invoice>().hasmany(i => i.invoice_file_list).withone().hasforeignkey(f => f.invoice_num); builder.entity<invoice>().hasone(i => i.invoice_business).withmany().hasforeignkey(i => i.merchant_id); }
 //.file为invoice_file_list类中字段属性,.invoiced_party为invoice_business字段属性
iqueryable<invoice> invoicelist = _postgredbcontext.invoice.asnotracking().include("invoice_file_list.file").include("invoice_business.invoiced_party");

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网