【发布时间】:2011-01-07 22:11:31
【问题描述】:
我有一个包含“transactions”和“transaction_lines”的数据库。事务具有基本的共享详细信息,事务行保存构成事务的组件的值。在传统 SQL 中,我会使用 SQL 事务(对不起,我们现在有一个模棱两可的词......)然后我会 INSERT INTO Transaction ...从事务表中的新行中获取 IDENTITY 键值,然后插入到我的 transaction_line 表中,使用 Transaction 表中的标识列作为外键。
有没有使用 linq 的好方法?
这是我目前所拥有的:
account_transaction ac = new account_transaction
{
transaction_date = DateTime.Now,
is_credit = isCredit,
account = (db.accounts.FirstOrDefault(a => a.account_id == accountid))
};
db.AddToaccount_transaction(ac);
db.SaveChanges();
我认为在 'AddToaccount_transaction(ac)' 和 'db.SaveChanges()' 之间,我需要添加我的 transaction_lines。
【问题讨论】:
标签: c# linq-to-sql