Expose a persistent DataSet that includes Change Tracking
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.
精彩评论