Read value which is committed

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 14-Dec-2010 06:28:28   

LLBLGEN 3.0 Release 8th December Oracle 9i/10g

I have used expression in code as follows

public static Int64 BillCounterPrepaidCardReCharge() { var adaptersmartcatrd = new DataAccessAdapter(); adaptersmartcatrd.StartTransaction(IsolationLevel.ReadCommitted, "BillCounter"); DataTable BillCounterDt = BillCounterPrepaidSmartCardDt(); Int64 BillCounterNo = Convert.ToInt32(BillCounterDt.Rows[0]["BillcounterId"]); var billcounter = new BillcounterEntity(); adaptersmartcatrd.FetchEntity(billcounter); billcounter.BillcounterId = BillCounterNo; billcounter.IsNew = false; billcounter.Fields[(int) BillcounterFieldIndex.Billnumber].ExpressionToApply = (BillcounterFields.Billnumber + 1); adaptersmartcatrd.SaveEntity(billcounter);

        adaptersmartcatrd.Commit();
        adaptersmartcatrd.Dispose();


    }

Problem: I want to know what is the value that is committed. If I use refetch after save, it fetches by adding expression once again thus giving incorrect output. I mean let us say DB value is 1, the line billcounter.Fields[(int) BillcounterFieldIndex.Billnumber].ExpressionToApply = (BillcounterFields.Billnumber + 1); will add 1+1 which becomes 2. Now when I say refetch after save is true, it returns 3 for me. But I need to see the ouput as 2. How can I achieve this. I cannot write one more fetch entity because another user might have committed another value by that time.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Dec-2010 09:36:44   
    using (var adapter = new DataAccessAdapter())
    {
        adapter.StartTransaction(IsolationLevel.ReadCommitted, "BillCounter");  
        
        var product = new ProductEntity();

        product.ProductId = 1;
        product.IsNew = false;
        product.Fields[(int)ProductFieldIndex.UnitsInStock].ExpressionToApply =
            (ProductFields.UnitsInStock + 1);
        adapter.SaveEntity(product);
        
        product = new ProductEntity(1);
        adapter.FetchEntity(product);

        adapter.Commit();
    }

Also note that your code has a fetchEntity which does nothing:

        var billcounter = new BillcounterEntity();
        adaptersmartcatrd.FetchEntity(billcounter);
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 14-Dec-2010 10:22:48   

Walaa wrote:

    using (var adapter = new DataAccessAdapter())
    {
        adapter.StartTransaction(IsolationLevel.ReadCommitted, "BillCounter");  
        
        var product = new ProductEntity();

        product.ProductId = 1;
        product.IsNew = false;
        product.Fields[(int)ProductFieldIndex.UnitsInStock].ExpressionToApply =
            (ProductFields.UnitsInStock + 1);
        adapter.SaveEntity(product);
        
        product = new ProductEntity(1);
        adapter.FetchEntity(product);

        adapter.Commit();
    }

Also note that your code has a fetchEntity which does nothing:

        var billcounter = new BillcounterEntity();
        adaptersmartcatrd.FetchEntity(billcounter);

Thanks Walaa, this was of great help