How to use IEnumerable as a navigation property instead of IList

c# domain-driven-design entity-framework entity-framework-6 ienumerable

Question

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.

enter image description here

1
0
9/10/2018 1:17:17 PM

Popular Answer

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.

0
9/10/2018 1:44:42 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow