Fluent API - one to many

放肆的年华 提交于 2019-11-30 08:40:33

In your model a User entity has many Histories with each history having a required User and the relationship has a foreign key called UserId:

modelBuilder.Entity<User>()
   .HasMany(u => u.Histories)
   .WithRequired()
   .HasForeignKey(h => h.UserId);

(The relationship must be required (not optional) because the foreign key property UserId is not nullable.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!