开发者

Expose a persistent DataSet that includes Change Tracking

开发者 https://www.devze.com 2023-03-11 17:54 出处:网络
I want to expose a WCF service operation that sends new records in a database. Each time the operation is invoked, it should return a DataSet object that includes only rows that have been added to the

I want to expose a WCF service operation that sends new records in a database. Each time the operation is invoked, it should return a DataSet object that includes only rows that have been added to the database since the last time the operation was invoked.

My question is whether this is possible by serializing the DataSet between calls and then using GetChanges() and AcceptChanges() methods.

Ie (pseudocode),

 [Operatio开发者_开发问答nContract]
 public DataSet GetDataSet() 
 {     
       DataSet ds = LoadDataSet();   // load a dataset from saved xml or binary

       DataSet newDs = GetRecordsFromDatabase(); // load dataset from database

       ds.Merge(newDs, true);  // somehow recognize which records in the newDs 
                               // load are new?
       return ds.GetChanges(); 
 }


Try:

ds.GetChanges(DataRowState.Added)

My suggestion: Do not serialize datasets. Maybe you can preserve the ID of the last record you inserted.

Regards, M.

0

精彩评论

暂无评论...
验证码 换一张
取 消