Can I create a transaction using ADO NET Entity Data Model?

Posted by Junior Mayhé on Stack Overflow See other posts from Stack Overflow or by Junior Mayhé
Published on 2010-05-13T22:51:59Z Indexed on 2010/05/13 23:04 UTC
Read the original article Hit count: 230

Hi

is it possible on the following try-catch to execute a set of statements as a transaction using ADO NET Entity Data Model?

[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Customer c)
{   
    try
    {
        c.Created = DateTime.Now;
        c.Active = true;
        c.FullName = Request.Form["FirstName"];
        db.AddToCustomer(c);
        db.SaveChanges();

        Log log = new Log();//another entity model object
        log.Created = DateTime.Now;
        log.Message = 
            string.Format(@"A new customer was created 
            with customerID {0}", c.CustomerID);
        db.AddToLog(log);

        db.SaveChanges();
        return RedirectToAction("CreateSuccess", "Customer");
    }
    catch
    {
        return View();
    }

}

Any thoughts would be very appreciated.

© Stack Overflow or respective owner

Related posts about ado.net-entity-data-model

Related posts about transactions