Quantcast
Channel: CSLA .NET
Viewing all articles
Browse latest Browse all 764

Strange issue saving child objects

$
0
0

Good day.

i have a strange issue, i have a quotation (invoice) form with child lines. if i add new lines and save it works perfectly, if i delete a line and save this too works fine. but i find that if i delete a couple if lines click save and then add new lines and click save the lines the deleted item are not deleted properly and the new lines are just saved to the database. what could be causing this issue? am i supposed to manually clear my deleted lines list at some point?i also fined that if i have 4 saved lines to begin with and click save that all 4 lines are saved, if i then remove 2 lines and save 2 lines are removed from the database, but if i then click add to create a new line and click save the deleted lines are put back and saved to the database. i should only have 3 lines in the table but i end up with  5 lines (2 original lines, 1 newly inserted line and the 2 lines previously deleted)

i have this code in my QuotationFactory:

public void UpdateChildren(QuotationLineList obj, Quotation q)
        {
          
            foreach (var item in GetDeletedList<QuotationLine>(obj))
            {
                this.Update(item, q);
            }

            foreach (QuotationLine item in obj)
            {
                this.Update(item, q);
            }
        }

which calls the following:

public QuotationLine Update(QuotationLine obj, Quotation q)
        {

            if (obj.IsDeleted)
            {
                if (!obj.IsNew)
                {
                    ExecuteDelete(obj.ID);
                
                }
                MarkNew(obj);
            }
            else
            {
                if (obj.IsNew)
                {
                    //Insert New data
                    obj.QUID = q.Id;
                    ExecuteInsert(obj);
                   
                }
                else
                {
                    //Update existing data
                    ExecuteUpdate(obj);
                  
                }
            }

           
          
            return obj;
        }

any help regarding this would be much appreciated.

 

 


Viewing all articles
Browse latest Browse all 764

Trending Articles