SubSonic DAL objects with round trip with WCF

Question: How do I keep the SubSonic objects dirty when they go back and forth through the Windows Communication Foundation service?

In particular:

I have a WCF service call that returns a collection of SubSonic (2.2) objects, for example:

// WCF server side
public MyObjectCollection GetAllMyObjects()
{
   // Retrieve a MyObjectCollection (SubSonic-generated class) from the DB
   return DB.Select().From<MyObject>.ExecuteAsCollection<MyObjectCollection>();
}

and another that allows the client to save them:

// WCF server side
public void SaveAllMyObjects(MyObjectCollection objs)
{
   objs.SaveAll();
}

On the WCF client side, I retrieve this collection (via the generated WCF proxy), I change some of its elements, and then I save it:

// WCF client side
MyObject[] allObjects = myWcfClient.GetAllMyObjects();
allObjects[3].SomeProperty = "Some other value";
myWcfClient.SaveAllMyObjects(allObjects);

However, what happens is that calling "objs.SaveAll () SubSonic does not save anything, because it does not" understand "that objs [3] has been changed, that is, no one has flipped the dirty bit in this column.

-, , ? , SubSonic , WCF?

+3
1

, , , -, SubSonic, . , , MyObjectCollection, MyObject, , , SubSonic, , , , . , :

// WCF server side
public void SaveAllMyObjects(MyObjectCollection objs)
{
   MyObjectCollection fakeColl = new MyObjectCollection();
   foreach (var oneObj in objs)
   {
       var oneFakeObj = new MyObject();
       oneFakeObj.Id = oneObj.Id;    // Primary key
       // Pretend oneFakeObj was just loaded from the DB
       oneFakeObj.IsNew = False;
       oneFakeObj.IsLoaded = True;
       // Copy all column values
       foreach (var col in MyObject.Schema.Columns)
       {
           oneFakeObj.SetColumnValue(col.ColumnName, oneObj.GetColumnValue(col.ColumnName));
       }
       fakeColl.Add(oneFakeObj);
  }
  fakeColl.SaveAll();
}
0

Source: https://habr.com/ru/post/1718876/


All Articles