开发者

Use last inserted ID with Subsonic Active Record

I am using SubSonic 3 (Active Record) as ORM. I have to insert data in 2 tables and use the ID of the inserted row in table 1 as foreign key in table 2. What is the best method to do this开发者_高级运维. I can save data to table 1 first and then use it's ID for insert in table 2 but that will be 2 queries, executed sequentially. Cant' I do this in a batch or transaction ?

Thanks


Short answer: no, or not easily.

Longer answer: If you can express what you want to do in a single SQL query, you can probably persuade SubSonic to do it for you. However, one query cannot insert into two different tables, so no joy.

Yes, you can batch queries, but you can't easily get the ID from one into another. You're probably better off with a stored procedure.

Yes, you can and should enclose them in a transaction, but that doesn't help.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜