Is it somehow possible to define navigation properties in EFCore with private or protected access level to make this kind of code work:
class Model {
public int Id { get; set; }
virtual protected ICollection<ChildModel> childs { get; set; }
}
I am not sure if that is possible, the whole model should be available and accessible at a low level with any restrictions on DTO's ViewModels etc
You have two options, using type/string inside the model builder.
Not 100% sure it works with private properties, but it should.
Update: Refactoring-safe version
Or use a backing field.
Alternatively try that with a property
Be aware, as of EF Core 1.1, there is a catch: The metadata modification must be done last, after all other
.HasOne/.HasMany
configuration, otherwise it will override the metadata. See Re-building relationships can cause annotations to be lost.