How to use IEnumerable
as a navigation property, I don't want to expose a List for the client developer and give him extra distracted,undesirable functionalities like Clear(),CopyTo()
.
So I did the following :
private readonly List<WorkTime> _assignedWorkTimes;
public virtual IEnumerable<WorkTime> AssignedWorkTimes { get => _assignedWorkTimes; }
But When I use EF Power tool
to render the model I see no relationship between the two entities.
Note: I make a unidirectional relationship (based on DDD
recommendations) with only a Foreign key in Worktime
to facilitate the data operations.
For creating one to many relationships the 'many' property must implement ICollection. See also https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/dd468057(v=vs.100).
Or, in other words, what you want is not possible with EF6.