MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

Csla.Web.Mvc: Why forceUpdate option? #629

Open GreggThelen opened 5 years ago

GreggThelen commented 5 years ago

Curious as to under what circumstances one would use the forceUpdate parameter SaveObject(child, true) in the base controller provided by CSLA for the MVC framework. Doesn't the object already know if it is new to use DataPortal_Insert and if not new to use DataPortal_Update?

rockfordlhotka commented 5 years ago

This is explained in the Using CSLA 4 book on ASP.NET.

The scenario is where a web page is displaying data for an existing domain object, and then the user changes something and clicks save. The user's intent is to update the existing data.

So you now have a choice. Either you Fetch the object and load it with the postback data, or you create an instance on the web server and load it with the postback data.

The Fetch approach is fine (maybe good), but does have a performance impact obviously.

The create a new object approach is also fine (maybe good), and is faster. But that object will have IsNew as true - when you need it to be false. So the forceUpdate option tells the data portal to treat the object as though IsNew was false.