设为首页 加入收藏

TOP

.netcore2.1 ef 使用外键关联查询
2019-10-10 18:14:55 】 浏览:362
Tags:.netcore2.1 使用 关联 查询
 
  //实体类
[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");

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C#中将long浮点数格式化为{H:min:.. 下一篇知道手机前三位后四位如何查找手..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目