views:

336

answers:

1

I have been looking at the examples for updating models in the MVC architecture. There are plenty updating the model where the linq (SQL or EF) is in the controller. And there are others where the service layer is used to fetch values. The only example I can find its going to be awkward to use with an IoC container.

What I'm looking to be able to do, is fetch a model object update it in the controller and then pass it back in and actually do the saving in the Service Class or dater layer underneath.

At present I'm stuck with the data context in the service class fetching the object

 public User GetUser(string username)
 {
  return dc.UserSet.WithUsername(username);
 }

doing the updates in the controller with UpdateModel

and then calling SaveChanges through through the service interface and relying on the fact that the model object is still connected.

 public void Save()
 {
  dc.SaveChanges();
 }

What I want is to be able to call something like: public void Update(User User)

A: 

Were you looking for something like this?

http://www.davidhayden.com/blog/dave/archive/2007/10/12/LINQToSQLAttachMethodAttachingDetachedBusinessEntitiesDataContextAttach.aspx

You may or may not care about concurrency. Simple apps could probably get away with a last in wins approach but for larger apps you may need to research concurrency with linq to sql.

Imran