Entity Framework Code First关系映射约定
一.本篇随笔目录:
1、外键列名默认约定
2、一对多关系
3、一对一关系
4、多对多关系
5、一对多自反关系
6、多对多自反关系
(…,具体看链接)
https://www.cnblogs.com/libingql/p/3353112.html#3
二.Fluent API
除了惯例原则与属性数据注解外,FluentAPI是另一种支持实体类配置设置的方式。与属性数据注解相比,它提供了更广泛的功能与设置弹性。实体类若同时设置了数据注解,则采用的优先权是“Fluent API” > “数据注解” > “惯例”。一旦设置了Fluent API 无论数据注解还是惯例规则均会被覆盖。
DbContext类定义的OnModelCreating 方法是最常调用FLuent API的地方,如下图所示:
public class SchoolContext: DbContext
{
public KTStoreContext():base("name=KTStore")
{
}
public DbSet<Product> Products { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//Write Fluent API configurations here
}
}
(…)
https://blog.csdn.net/xuchen_wang/article/details/98874127