views:

49

answers:

1

Hi,

I have an ASP.NET MVC application that uses LINQ2SQL as the database layer. I can save data back to the database no problem but I've came across a few issues when trying to save using a wizard-type scenario where data is collected over a few different forms but not saved to the database until the last form "Save" button is clicked.

At first I tried adding new objects to the datacontext, using InsertOnSubmit() or DeleteOnSubmit() and on the final page using SubmitChanges() to commit to the database. The problem with this is that if I tried to DeleteOnSubmit() an object that hadn't been submitted yet I would get an error.

I got round it eventually by writing a lot of code to manage the state of each object (insert, update or delete) and then on the final submit I make all changes to the DataContext before saving.

I'm wondering if there is a better way of managing the state of objects across pages using LINQ2SQL or if the manual code is the best way round it?

A: 

If you use TempData["key"] = data; you can pass data between redirections.

It uses session state but that can be overriden using you own provider that implements ITempDataProvider (probably the default will work you though!)

I'd build object through wizard and then do one SubmitChanges() in last page of wizard.

Kindness & HTH,

Dan

Daniel Elliott