Entity创建一对一关系

Area类

public virtual User User { get; set; }

User类

public virtual Area Area { get; set; }

Context类

modelBuilder.Entity<Area>()                        //巡检区域-区域负责人

.HasOptional(a => a.User)

.WithOptionalDependent()

.Map(x => x.MapKey("UserID"));

modelBuilder.Entity<User>()                        //巡检区域-区域负责人

.HasOptional(u => u.Area)

.WithOptionalDependent()

.Map(x => x.MapKey("AreaID"));

上一篇:GoogleStyle格式化代码


下一篇:解决SVN更新代码是出现previous operation has not finished; run cleanup if it was interrupted这个错误