1.Fluent API配置Model试用行更广
2.使用方法:
public class TransferConfig: EntityTypeConfiguration<TransferInfo> { public TransferConfig() { Property(t=>t.Money).HasPrecision(20,2); } }
注意:在普通项目中,必须显示添加该配置
public class MyContext : DbContext { public MyContext() : base("name=MyContextLocal") { } public virtual DbSet<Customer> Customers { get; set; } public virtual DbSet<CardInfo> CardInfos { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new CustomerConfig()); base.OnModelCreating(modelBuilder); } }
在MVC中,会自动添加
3.一对一关系配置