Best practices for using the Entity Framework with WPF DataBinding [closed] Best practices for using the Entity Framework with WPF DataBinding [closed] wpf wpf

Best practices for using the Entity Framework with WPF DataBinding [closed]


You need to implement a repository pattern to seperate WPF concerns from EF

Then you can use generics to reduce the complexity of the EF to CollectionViewSource handling

A well designed repository should reduce code levels and enable any ORM to be substituted (required for decent testing)

Some ideas for this are in here

http://blog.nicktown.info/2008/12/10/using-a-collectionviewsource-to-display-a-sorted-entitycollection.aspx


Also, I dont think you need to do a ToList() here. I believe ObservableCollection() takes an IEnumerable which families already is. If you do a ToList, and then pass that to the ObservableCollection, then I think you will loop through all your records twice.

familyOC = new ObservableCollection<Family>(families.ToList());

Instead, try this, which should be a bit faster:

familyOC = new ObservableCollection<Family>(families);


I understand where you're coming from. This article by Josh Smith helped me change (or start to change) mindset so that you can some benefit from WPF rather than seeing it as a weird, obstructive, hard-to-debug and unfriendly framework!