Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (19 sloc) 1.65 KB
layout title date tags
Modelbinding a complex entity framework/Linq to Sql model to mvc
2009-03-14 06:41:00 +0100
asp.net_mvc c# Entity_Framework Linq_to_Sql

For a couple of days now I've been trying to "ModelBind" a more complex model (based on the Entity framework) to a controller action. The problems I've been having are mostly related to the amount of code for this task. I'm therefore thinking of ways to reduce the complexity. The main problem is that it's not directly possible to bind to ordinary EF/LS-graphs.

  • Separate object graph. One solution could be to have a separate object graph for use in with the view. That seems more than wastefull since we want to edit everything on this page and thus end up having to maintain extra objects when we have the EF/LS ones.

  • A revised binding to the EF/LS objects. If my modelbinder treated the EF/LS objects in the correct maner then my problems would be solved. Problem is though that I need connected objects in the binding. That implies a UpdateModel pattern with the object context visible from the controller. Not a beautiful solution though.

I've written a small mvc application with a simple (complex model). I've a main entity Smurf. The Smurf entity has several SmurfChild records related to it:

smurf model{:height="320px" width="278px"}

The model binding I'm trying to do is the following:

public ActionResult EditAll_CustomBinder(
        IList<smurf> smurfs

I'm editing a list of smurfs and the related smurf children in the view.