codefirst 书写配置类,用于entity与数据库中表或view映射
1、对应表或视图都用this.ToTable("SimpleCompanyLoanView", "dbo"); dbo为schema
2、配置主键。尤其是视图需要有特定识别的“主键”,不然报错,实在没有可以在创建视图时加行号。用this.hasKey,如果是联合主键是new{A,B}。this.HasKey(m => new{m.CompanyNo,m.CurrentYear,m.CurrentMonth});
3、配置具体字段 this.Property(m => m.CompanyName);
4、忽略字段(即entity中个别字段不在数据库表中) this.Ignore(m=>m.Name);
public SimpleCompanyLoanViewConfiguration()
{
this.ToTable("SimpleCompanyLoanView", "dbo");
this.HasKey(m => new{m.CompanyNo,m.CurrentYear,m.CurrentMonth});
this.Property(m => m.CompanyName);
this.Property(m => m.CompanyNo);
this.Property(m => m.FirstBankName);
this.Property(m => m.SecondBankName);
this.Property(m => m.FirstLoanAmount);
this.Property(m => m.SecondLoanAmount);
this.Property(m => m.LoanAmountSum);
this.Ignore(m=>m.Name);
}