WPF and EF – Updating code generation for data binding

I am new to WPF and EF. I want to make an application using WPF, EF and a local MSSQL database.

I choose the "Database First" approach. I created the database, the tables and added a model.

Then I read this (here):

EF generates code from your model using T4 templates. The templates shipped with Visual Studio or downloaded from the Visual Studio gallery are intended for general purpose use. This means that the entities generated from these templates have simple ICollection<T> properties. However, when doing data binding using WPF it is desirable to use ObservableCollection for collection properties so that WPF can keep track of changes made to the collections. To this end we will to modify the templates to use ObservableCollection.

I am not used to using a tool like Visual Studio that automates a lot. So I came across this and was surprised. It kinda seems like "hack". Visual Studio does everything for you and suddenly you need to modify this generated code.

Can anyone explain this to me and put it into context for me?

Thanks

by Orvel via /r/csharp

Leave a Reply