Manish Pansiniya's Blog

.NET, C#, Javascript, ASP.NET and lots more…:)

Subsonic and Transaction

with one comment

The one of the hot topic about subsonic is Trasaction support. It doesn’t provide the transactioin support. So i decided to change the code of subsonic to provide the transaction code. I thought about how can we provide the easiest way for transaction for temporary purpose and following is the solution

Please let me know if anybody needs the files i have changed. I change the QueryCommand and DataService class.

try
        {
            QueryCommandCollection qry = 
               new QueryCommandCollection();
            Country ct = new Country();
            ct.CountryColumn = "Test";

            QueryCommand q = 
            ct.GetInsertCommand(User.Identity.Name);
            q.IdForTransaction = 
               Country.Columns.CountryId;
            qry.Add(q);
            State st = new State();
            st.StateColumn = "State";
            QueryCommand qq = 
              st.GetInsertCommand(User.Identity.Name);
            qq.IdWithTransaction = 
                  Country.Columns.CountryId;
            qry.Add(qq);


            SubSonic.DataService.ExecuteTransaction(qry);

        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        finally
        {
        }
        

Now, if you see above code. There is two table called Country and State. This is just sample to let you understand this. In realtime, this would not be the case. Suppose, we need to add country and state by using transaction.
You need to set IdForTrasaction property of QueryCommand to the column name which you need as Identity to insert into other table. In above case, we need to insert CountryId from country table into the State table. So for country’s QueryCommand, I set IdForTransaction as CountryId column.

Now for State table, I need to provide IdWIthTransaction property as CountryId. So at the time of inserting the record, it checks IdWithTransaction property and add the parameter if one is supplied.

Simple huh 🙂

Advertisements

Written by Manish

March 2, 2007 at 2:11 pm

Posted in Uncategorized

One Response

Subscribe to comments with RSS.

  1. Hi,

    I also have this problem. Can u pls send me that files

    Thanks
    Sanjaya

    Sanjaya

    March 9, 2007 at 8:24 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: