SubSonic Forums
All Your Database Are Belong To Us

SubSonic Transaction

Latest post 08-19-2008 3:23 PM by yitzchok. 3 replies.
  • 08-18-2008 5:07 AM

    • soham85
    • Top 100 Contributor
    • Joined on 07-18-2008
    • Kolkata
    • Posts 20

    SubSonic Transaction

    Hi all I'm trying to perform a transaction where there are two updates on the same table and one insert to another table. Here is the code that I've written :

    List<SubSonic.SqlQuery> coll = new List<SubSonic.SqlQuery>();
    coll.Add(new SubSonic.Update(WestsideBank.CustomerAccount.Schema).Set(WestsideBank.CustomerAccount.BalanceColumn).EqualTo(ChangedDesBalance).Where(WestsideBank.CustomerAccount.AccountIDColumn).IsEqualTo(desacid));
    coll.Add(new SubSonic.Update(WestsideBank.CustomerAccount.Schema).Set(WestsideBank.CustomerAccount.BalanceColumn).EqualTo(ChangedSrcBalance).Where(WestsideBank.CustomerAccount.AccountIDColumn).IsEqualTo(srcacid));
    coll.Add(new SubSonic.Insert().Into(WestsideBank.Transaction.Schema).Values("newid()", srcacid, amttrans, "getdate()", desacid, ChangedSrcBalance));
    SubSonic.SqlQuery.ExecuteTransaction(coll);

    Now this code is giving me an error saying that

    1.Error 1 The best overloaded method match for 'System.Collections.Generic.List<SubSonic.SqlQuery>.Add(SubSonic.SqlQuery)' has some invalid arguments C:\Inetpub\wwwroot\WestsideBank\Customers\Transfers.aspx.cs 41 

    2.Error 2 Argument '1': cannot convert from 'SubSonic.Insert' to 'SubSonic.SqlQuery' C:\Inetpub\wwwroot\WestsideBank\Customers\Transfers.aspx.cs 41 

    Now I think that my choice of "type class" here is wrong but what should I use to support both insert and update? Or is there any other better way of doing it.

    Also I used sql "newid()" and "getdate()"  inside the insert statement. Is it the right way to do it or is there any subsonic special function which does this for me. And also should I use quotes for variables that I use inside the "insert()" parameter. Please help.

    Regards,
    Soham Dasgupta

    Filed under:
  • 08-18-2008 2:23 PM In reply to

    Re: SubSonic Transaction

    Reply |Contact |Answer

    To do this you can't se the helper methods

    http://subsonicproject.com/active-record/transactions/

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 08-19-2008 12:50 AM In reply to

    • soham85
    • Top 100 Contributor
    • Joined on 07-18-2008
    • Kolkata
    • Posts 20

    Re: SubSonic Transaction

    Thanks man. That page was exceptionally helpfull. But one thing I did not understand is that

    coll.Add(p1.GetUpdateCommand(Environment.UserName));

    coll.Add(p2.GetUpdateCommand(Environment.UserName));

     

    What is with environment.username? What is that? What is its purpose.

    Regards,
    Soham Dasgupta

  • 08-19-2008 3:23 PM In reply to

    Re: SubSonic Transaction

    http://msdn.microsoft.com/en-us/library/system.environment.username.aspx

    It is then name of the logged in user to the system

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

Page 1 of 1 (4 items) | RSS