//實體類 [Table("invoiceinfo", Schema = "obs")] public class invoice { [Key] public string invoice_num { get; set; } public string merchant_id { get; set... ...
//實體類
[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");