将生成的id从表1(主键)传递到表2(外键)?

时间:2009-11-19 16:05:35

标签: c# sqlite subsonic transactions

我正在使用(评估:))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

            }
        }

请指教。感谢

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

这就是我要找的东西。

       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);
                }
            }
        }