How can I make a collection of Set entities in the Entity Framework?

Let's say that I am building a model from a blank canvas in EF, and I have a one-to-many relationship in the model (Category-> Product or something else). How can I make this collection (Category.Products) Set (HashSet or similar) instead of a collection so that I can apply set constraints (such as uniqueness) at the model level?

+4
source share
1 answer

I recently switched to using POCO with Linq-To-Sql and really wanted freedom to let it not use EntitySet and others. Therefore, I think POCO is the answer for you, but I suspect (I have not investigated it, so I can’t answer definitively), there will be restrictions on what types you can use for your associations and the framework (EF or L2S) will still be able to use them. For example, you may have to use something that comes from IList or something else.

I looked at something vaguely similar a little bit back and found that one of the features of EntitySet is the ability to subscribe to add and remove events. There is an ObservableCollection type that also has similar functionality, so you can explore them. Otherwise, you are most likely stuck on your own.

+2
source

Source: https://habr.com/ru/post/1339941/


All Articles