开发者

Passing generated id from table 1 (primary key) to table 2 (foreign key)?

I am using (evaluating :)) Subsonic ActiveRecord mode for accessing sqLite. Need transaction to work. Regular stuff... Of ocurse!

Following snippet explains the desired logic. I couldn't find the right example in docs.

        using (TransactionScope ts = new TransactionScope())
        {
            using (SharedD开发者_如何学运维bConnectionScope 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

            }
        }

Please advise. Thanks


http://www.sqlite.org/c3ref/last_insert_rowid.html


Here is what I was looking for.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜