UOW update not working

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 11-Jul-2012 13:01:26   

LLBLGen 3.5 .Net framework 4.0 C# windows application SQL Server 2005

I am trying to do insert and udpate entity but the line which is in **bold **below does not update the entity. Created trace file to trace queries but noticed it did not generate update query at all. Unable to find reason, hence request help.

var Uowguestregistrationsave = new UnitOfWork(); try { Int64 BillNo = 2; //BillCounter.BillCounterGuestRegistaration(); if (BillNo == 0) { MessageBox.Show("Failed to generate bill number"); return 0; }

            string[] Uno = Convert.ToString(InserId.Rows[0]["USERNO"]).Split(' ');
            ............
            var GuestRegistration = new GuestregnheaderEntity();

            .............

            Uowguestregistrationsave.AddForSave(GuestRegistration);

            for (int i = 0; i < dgridguest.Rows.Count - 1; i++)
            {
                ...........
            decimal total = Convert.ToDecimal(InserId.Rows[0]["TOTAL"]);
            int Monthlybillid = Convert.ToInt32(InserId.Rows[0]["MONTHLYBILLID"]);
            var monthlybill = new MonthlybillEntity(Monthlybillid);

            if (Monthlybillid == 0) return 0;
            {
                monthlybill.IsNew = false;

                monthlybill.Fields[(int) MonthlybillFieldIndex.Debitamount].ExpressionToApply =
                    (MonthlybillFields.Debitamount + total);

                monthlybill.Fields[(int) MonthlybillFieldIndex.Balanceamount].ExpressionToApply =
                    (MonthlybillFields.Balanceamount + total);

            ** Uowguestregistrationsave.AddForSave(monthlybill);**

            }

           .........
                Uowguestregistrationsave.AddForSave(monthlybilldetail);
            }
            else
            {
                var monthlybilldetail = new MonthlybilldetailEntity(MonthlybilldetailId);
                monthlybilldetail.IsNew = false;
                monthlybilldetail.Fields[(int) MonthlybilldetailFieldIndex.Debitamount].ExpressionToApply =
                    (MonthlybilldetailFields.Debitamount +
                     total);
                Uowguestregistrationsave.AddForSave(monthlybilldetail);

            }


            int succeeded = Uowguestregistrationsave.Commit(
                    new Transaction(IsolationLevel.ReadCommitted, "UOW"), true);
                return succeeded;
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jul-2012 20:35:17   

If you check monthlybill.IsDirty, it would be false, and thus the framework won't pick it up for update.

Expressions can be used for UpdateMulti calls or Uow.AddUpdateMulti.

Also make sure the call reaches this part of code as the if condition returns 0 if true.