当我调用db.SaveChanges()
方法时,我遇到了问题。即使在connectionString中,当我从数据库中读取时,我有MultipleActiveResultSets=True
并且我使用ToList()
方法,当我拨打db.SaveChanges()
时,我就是从问题的标题中得到错误。
这是我的连接字符串:
<connectionStrings><add name="DBEntities" connectionString="metadata=res://*/DBEntities.csdl|res://*/DBEntities.ssdl|res://*/DBEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=.\ServerName;initial catalog=DatabaseName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
这是我的c#代码:
db.SaveChanges();
int errorTrans = (from el in this.curentHandbackFile.Root.Element("data").Elements("Transaction") where el.Attribute("rrc").Value.Contains("_NOK_") select el).Count();
IEnumerable<XAttribute> integratedTrans = from el in this.curentHandbackFile.Root.Element("data").Elements("Transaction").Attributes("rrc") where el.Value.Contains("_OK_") select el;
int warningTransactionsCount = integratedTrans.Where(trans => trans.Value != ReturnCodes.RecordCodes.TransactionImported.Key).ToList().Count;
int successTransactionsCount = integratedTrans.Where(trans => trans.Value == ReturnCodes.RecordCodes.TransactionImported.Key).ToList().Count;
_import.Successes = successTransactionsCount;
_import.Errors = errorTrans;
_import.Warnings = warningTransactionsCount;
db.SaveChanges();
当我第二次拨打db.SaveChanges()
时,我收到了错误消息。知道为什么吗?
PS:我使用的是.NET 3.5