You have two options using the type / string inside the model builder.
modelBuilder.Entity<Model>(c => c.HasMany(typeof(Model), "childs") .WithOne("parent") .HasForeignKey("elementID"); );
Not 100% sure that it works with private properties, but it should.
Update: safe version with refactoring
modelBuilder.Entity<Model>(c => c.HasMany(typeof(Model), nameof(Model.childs) .WithOne(nameof(Child.parent)) .HasForeignKey("id"); );
Or use the support box.
var elementMetadata = Entity<Model>().Metadata.FindNavigation(nameof(Model.childs)); elementMetadata.SetField("_childs"); elementMetadata.SetPropertyAccessMode(PropertyAccessMode.Field);
Alternatively try using the property
var elementMetadata = Entity<Model>().Metadata.FindNavigation(nameof(Model.childs)); elementMetadata.SetPropertyAccessMode(PropertyAccessMode.Property);
Remember that with EF Core 1.1 there is a catch: the metadata change should be the last, after all other .HasOne/.HasMany , otherwise it will override the metadata. See Restoring Relationships may result in loss of annotations .
Tseng source share