Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View - ViewModel - Entity Framework 4

I'm looking for a simple way to link a view to a viewmodel and then to Entity Framework through databinding.

Can someout out there give me some pointers. What I'm looking for is a very simple implementation that would allow the view to automatically list all the contents of for example a one field table and for changes in the view to be propogated back to the database through EF.

AAfter spending a long time looking I'm still searching for a way to do this and any help would be very much appreciated.

Thanks,


1 Answers

Technically using a ViewModel means you don't actually bind to your entities. Your ViewModel classes should have everything on them that is needed by the view (and yes, this can cause what feels like duplication, but it's for the greater good), and therefore you don't even have this problem.

You can ease the pain of duplication by implementing something like AutoMapper to avoid the legwork of "left to right" coding where you're just copying properties across.

If you are binding a list, consider having an EmployeeListViewModel that has a property of type IList<EmployeeViewModel> on it, so that you're still not binding your entities directly to the view. This is useful because you can then reuse that EmployeeViewModel for a single-record detail view.

like image 144
Neil Barnwell Avatar answered Dec 31 '25 19:12

Neil Barnwell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!