C# 实体框架Fluent API:复合键->;循环关系
共有3个表格:C# 实体框架Fluent API:复合键->;循环关系,c#,postgresql,entity-framework,ef-code-first,entity-framework-migrations,C#,Postgresql,Entity Framework,Ef Code First,Entity Framework Migrations,共有3个表格: 父母 儿童 一个孩子到另一个孩子的过渡(跳跃) 比如想象书。是书本身,它将是父母的餐桌。孩子们,这本书有几页。页面上有脚注和其他页面的链接,它会跳转 对于儿童,我使用复合键(new{ChildId,ParentId}),因为与书籍类似,第1页可以在各种书籍中找到。在现实世界中,字符串的ID包含一个代码 桌子跳了起来。它描述了一个脚注。将转换的页面ID(SourceChildId)和将转换的页面ID(TargetChildId)。因为转换发生在同一本书(父)中,该书使用一个字段
- 父母
- 儿童
- 一个孩子到另一个孩子的过渡(跳跃)
modelBuilder.Entity<Child>().HasMany(x => x.JumpsFrom).WithRequired().HasForeignKey(x => new { x.SourceId, x.ParentId });
modelBuilder.Entity<Child>().HasMany(x => x.JumpsTo).WithOptional().HasForeignKey(x => new { x.TargetId, x.ParentId });
modelBuilder.Entity().HasMany(x=>x.JumpsFrom).WithRequired().HasForeignKey(x=>new{x.SourceId,x.ParentId});
modelBuilder.Entity().HasMany(x=>x.JumpsTo).WithOptional().HasForeignKey(x=>new{x.TargetId,x.ParentId});
2) 在设置Parent.FirstChildId之前,我是调用context.SaveChanges()的
已解决问题项目:
我认为这个问题会导致Jump.ParentId和Jump.Source.ParentId(具体而言)不一样。。。可以通过flyent API进行设置吗?