Re-use of database object in sub-sonic

Posted by cantabilesoftware on Stack Overflow See other posts from Stack Overflow or by cantabilesoftware
Published on 2010-03-01T01:01:40Z Indexed on 2010/05/12 5:44 UTC
Read the original article Hit count: 293

Yet another newbie SubSonic/ActiveRecord question. Suppose I want to insert a couple of records, currently I'm doing this:

using (var scope = new System.Transactions.TransactionScope())
{
    // Insert company
    company c = new company();
    c.name = "ACME";
    c.Save();

    // Insert some options
    company_option o = new company_option();
    o.name = "ColorScheme";
    o.value = "Red";
    o.company_id = c.company_id;
    o.Save();
    o = new company_option();
    o.name = "PreferredMode";
    o.value = "Fast";
    o.company_id = c.company_id;
    o.Save();

    scope.Complete();
}

Stepping through this code however, each of the company/company_option constructors go off and create a new myappDB object which just seems wasteful.

Is this the recommended approach or should I be trying to re-use a single DB object - and if so, what's the easiest way to do this?

© Stack Overflow or respective owner

Related posts about subsonic

Related posts about subsonic3