dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.65k stars 3.15k forks source link

T4 template for scaffolding data-binding entity types using INotifyPropertyChanged etc. #15515

Open ComptonAlvaro opened 5 years ago

ComptonAlvaro commented 5 years ago

Until now, i get the entities using this command:

Scaffold-DbContext "Server=localhost\SQLExpress;Database=MiBaseDatos;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

But I see that the default collection is hashset, but I know that EF Core can work with property changes, and there is a ObservableHashSet collection, but I would like to know if there is some way to set the type of collection that I want, because if not, I would have to change one by one the collections in all my entities.

Thanks.

ErikEJ commented 5 years ago

EF Core Power Tools with Handlebars templates will enable you to do this.

ajcvickers commented 5 years ago

Related to #4038, but it could be useful to have a mode that scaffolds for data-binding. However, in that case ObservableHashSet would not be appropriate--we would scaffold ObservableCollection for WPF/UWP, and ObservableBackedBindingList for Win Forms.

ComptonAlvaro commented 5 years ago

Why would it be the reson to use ObservableCollection? Now it is used a hashset for collections because I guess for performance is better because because to get an element it is O(1), but if now the collections will be ObservableCollections, wouldn't it make that to lose performance?

Just I am wondering why ObserbableHashSet is not appropiate in this case.

Thanks.

ajcvickers commented 5 years ago

@ComptonAlvaro It's because ObservableHashSet does not have a stable order. It's fine for notifications, but data binding requires that the order of other items not change when a different item is inserted or removed.

ComptonAlvaro commented 5 years ago

Thanks for the answer, it is good to learn new things.