查询已插入但尚未提交的记录的上下文
我在 stackoverflow 和 www 上搜索了又搜索,但没有找到这个问题的答案。
我循环遍历许多记录,并在某些条件下将新记录插入表 A。然后我再次循环另一个数据源(无法与第一个数据源合并),如果是这种情况,我想将新记录插入到同一个表A中。我只想在过程结束时提交记录,但如果我只是插入它们,它会给出主键冲突错误。
注意:linq 不管理主键。可能是因为我对 linq 有点菜鸟,并且真的不知道如何让 linq 与 Oracle 序列一起工作。
我的问题是如何检查我插入的记录的现有上下文。这就是我正在做的事情。
foreach(var rec in recordList1)
{
...
dataContext.InsertOnSubmit(obj);
}
foreach(var rec in recordList2)
{
if ( ! [check context here for existing record] )
{
...
dataContext.InsertOnSubmit(obj);
}
}
dataContext.SubmitChanges();
我尝试以不同的方式查询上下文,但它只会返回提交的值。
提前致谢! 此致。
I've searched and searched stackoverflow and www, but have found no answers to this question.
I am looping through a number of records and under certain conditions I'm inserting new records into table A. Then I'm looping again on another data source (which cannot be merged with the first one), and if that be the case, I want to insert new records into the same table A. I only want to commit the records at the end of the process, but it'll give a primary key violation error if I just insert them.
Note: linq is not managing primary keys. Probably because I'm sort of a noob with linq and don't really know how to get linq to work with Oracle sequences.
My question is how do I check the existing context for the records I have inserted. This is what I am doing.
foreach(var rec in recordList1)
{
...
dataContext.InsertOnSubmit(obj);
}
foreach(var rec in recordList2)
{
if ( ! [check context here for existing record] )
{
...
dataContext.InsertOnSubmit(obj);
}
}
dataContext.SubmitChanges();
I've tried querying the context in different ways, but it'll only return committed values.
Thanks in advance!
Best regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要访问数据上下文中插入、更新、删除的对象,您需要调用 GetChangeSet。
To access the objects inserted, updated, deleted in the datacontext you need to call GetChangeSet.