C# 数据集未保存数据
这是我第一次使用数据集。下面是我的代码C# 数据集未保存数据,c#,C#,这是我第一次使用数据集。下面是我的代码 var transactionSet = new ModelExecutionContext() { TransactionSet = new DataSet() { Tables = { new DataTable() { TableName = "transaction_history"
var transactionSet = new ModelExecutionContext()
{
TransactionSet = new DataSet()
{
Tables = { new DataTable()
{
TableName = "transaction_history"
}
}
}
};
transactionSet.TransactionSet.Tables["transaction_history"].Columns.Add().ColumnName = "retailer_reference_id";
var retailerReferenceIdRow = transactionSet.TransactionSet.Tables["transaction_history"].NewRow();
retailerReferenceIdRow["retailer_reference_id"] = 8;
transactionSet.TransactionSet.AcceptChanges();
我正在一个有数据集的类中对一个方法进行单元测试。我试图模仿那些数据集。我想transactionSet.transactionSet.AcceptChanges()
将把更改保存到数据集中,但在执行过程中,我得到上下文?.TransactionSet?.Tables[“transaction\u history”]?.Rows.Count
=0
我的代码有什么错误吗?创建行的对象后,需要将行添加到表中
transactionSet.TransactionSet.Tables["transaction_history"].Rows.Add(retailerReferenceIdRow);