Quantcast
Channel: CSLA .NET
Viewing all articles
Browse latest Browse all 764

Using SaveObject() in Mvc controller

$
0
0

Hi,

I am working on a Mvc4-project and I am wondering why I rather should use the method SaveObject() instead of myObject = myObject.Save() when inserting or updating the db?

The beginning of my code in my controller looks like the following:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

publicclassHomeController : Csla.Web.Mvc.Controller, IModelCreator

{

 

 

 

  publicobject CreateModel(Type modelType)

  {

 

 

 

    if (modelType.Equals(typeof(CustomerEdit)))

 

 

 

      returnCustomerEdit.NewCustomer();

 

 

 

    else

 

 

 

      returnActivator.CreateInstance(modelType);

  }

 

 

 

 

  publicViewResult Index()

  {

 

 

 

    return View();

  }

  [

 

HttpPost]

 

 

 

  publicViewResult Index(CustomerEdit model)

  {

 

 

 

    if (ModelState.IsValid)

    {

 

 

 

      SaveObject(model,

 

false);

    .

    .

    .

    .

and so on.

So again, my question in this example is why it is better to use 

      SaveObject(model, false);

instead of simply doing as usual

      model = model.Save();

 

Thanks,

Peter


Viewing all articles
Browse latest Browse all 764

Trending Articles