【发布时间】:2014-02-13 21:28:51
【问题描述】:
这是我的编码。它显示错误,例如 在提供程序连接上启动事务时出错。有关详细信息,请参阅内部异常。
DemoEntities db = DemoEntities.CreateNewDemoEntity();
var query = (from f in db.Product_Table
where f.ReportID == reportID && f.StateID == stateID
select f);
foreach(var q in query)
{
Custom_Search_Transformation cst = new Custom_Search_Transformation()
{
CustomerID = customerID,
StateID = stateID,
FullProductID = q.FullProductID
};
db.Custom_Search_Transformation.AddObject(cst);
db.SaveChanges();
}
【问题讨论】:
-
“详情见内部异常”是有原因的。
-
我发现了问题 db.SaveChanges();应该在 foreach 循环之外
-
当然,但是在 SO 问题中,显示内部异常告诉您的内容总是一个好主意。
标签: c# linq entity-framework