[英]Insert generated primary key as foreign key in different table from controller
[英]Passing generated id from table 1 (primary key) to table 2 (foreign key)?
我正在使用(evaluating :))Subsonic ActiveRecord模式訪問sqLite。 需要交易才能工作。 常規的東西。。。
以下代碼段說明了所需的邏輯。 我在文檔中找不到正確的示例。
using (TransactionScope ts = new TransactionScope())
{
using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
{
// insert data in table 1 with primary key column. Save the id returned for later use.
// insert data in table 2 with a foreign key column. Use the Id generated in table 1.
// ts.commit here
}
}
請指教。 謝謝
這是我一直在尋找的東西。
using (var ts = new TransactionScope())
{
using (SharedDbConnectionScope scope = new SharedDbConnectionScope())
{
try
{
document.Save();
documentsDatum.DocumentId = document.Id;
documentsDatum.Save();
ts.Complete();
}
catch (Exception ex )
{
throw new Exception("trx failed " + ex.Message, ex);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.