15.8. Adding, Updating, and Deleting Objects

The processes of adding, updating, and deleting objects is simple; you just have to keep in mind that these actions must be performed within the scope of a transaction.

To add an object, you need to create a new instance of a class that represents the object, add it to the scope provider, and call the Commit() method. See Listing 15-14.

Example 15.14. Adding a New Object
IObjectScope nwd = NorthwindScopeProvider.ObjectScope();
nwd.Transaction.Begin();
try
{
    var cat = new Category();
    cat.CategoryName = "Oriental Imports";
    cat.Description = "Food imported from Asia";
    cat.DisplayOrder = 100;
    nwd.Add(cat);
    nwd.Transaction.Commit();
}
catch (Exception)
{
    nwd.Transaction.Rollback();
}

For updating records, ...

Get Pro Telerik ASP.NET and Silverlight Controls: Master Telerik Controls for Advanced ASP.NET and Silverlight Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.