4
我在插入值表QueryList
如何獲得多個插入的標識值在實體框架
[QueryID] [WorkItemID] [RaisedBy]
1 123 xyz
2 234 abc
其中QueryID
是Identity
列。
我正在使用一個foreach
循環並一次插入多個值。我的問題是如何讓實體框架3.5
所有新插入的Identity
值。這是我的代碼
using (TransactionScope currentScope = new TransactionScope())
{
Query newQuery = new Query();
foreach (long workItemId in workItemID)
{
newQuery = new Query();
...
currentScope.Complete();
success = true;
}
}
entityCollection.SaveChanges(true);
int QueryID = newQuery.QueryID; //It gives me last 1 Identity value
當然 - 你是對的 - 早上太早了:-)大腦還沒有加速。 ....:_) – 2013-04-08 06:39:53
非常感謝..它的工作正常。 curentScope.Complete(); 應該出現在foreach循環之外 – Somashekhar 2013-04-08 07:08:17