Synchronize Collections

Aug 2, 2011 at 6:41 PM
Edited Aug 2, 2011 at 6:42 PM

I'm using the LinqConnect ORM coupled with the LinqEntityBase.cs as a base class for each of the objects generated by the ORM.  I'm using ASP.Net MVC 3.0 as the client.  The server gathers an entitiy (complete with many child entities) and sends it over to the client in a disconnected state.  All of the data on the client is manipulated via jquery/javascript and sent back to the server to be saved.  Right now, I'm struggling to update the child entity collections with changes made on the client.  The client will send over a JSON serialized object.  We use AutoMapper to map the ViewModel in the ORM object (bank).  Here is where I'm lost.  I get the original entity (existingBank) and try to figure out what has changed in the child entities Bankclasses and BankLimits using the ProcessUpdates extension method.  This isn't working very well.  It seems to understand what it should add, but doesn't delete any of the child entities.  Clearly, I'm doing something wrong.  Any suggestions on how to handle synchronizing data would be welcome.  Thanks.

Bank existingBank = rep.FindById(bank.Bankkey);

 existingBank.SetAsChangeTrackingRoot(true);

//Add/Remove BankClasses
existingBank.Bankclasses.ProcessUpdates(bank.Bankclasses);

//Add/Remove BankLimits
existingBank.BankLimits.ProcessUpdates(bank.BankLimits);

 public static EntitySet ProcessUpdates(this EntitySet source, EntitySet delta) where T : LINQEntityBase
        {
            //Remove T that have been deleted
            foreach (var x in source)
            {
                if (delta.ContainsUsingEquals(x) == false)
                {
                    x.SetAsDeleteOnSubmit();
                }
            }

            //Check for new T
            foreach (var x in delta.ToList())    //Using ToList() to create a copy to prevent having an exception thrown regarding changing the collection
            {
                if (source.ContainsUsingEquals(x) == false)
                {
                    source.Add(x);
                }
            }
            return source;
        }

Aug 4, 2011 at 4:17 PM

It's a defect with ORM.  Nevermind.