为什么没有“UpdateOnSubmit”方法? [英] Why is there no "UpdateOnSubmit" method?

查看:117
本文介绍了为什么没有“UpdateOnSubmit”方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过"UpdateOnSubmit"排队一系列插入内容。在"SubmitChanges"上进行交易的方法,如果有任何失败,则使用事务回滚。但是,我对如何管理更新感到困惑,因为似乎没有一个平等的"UpdateOnSubmit"。这可以包含在SubmitChanges集合中。

I can queue up a series of Inserts via the "UpdateOnSubmit" method that are transacted on "SubmitChanges", with a transaction rollback if any fail. However, I am confused on how updates are managed as there does not seem to be an equilivent "UpdateOnSubmit" that can be included in the SubmitChanges collection.

我似乎在这里缺少一些基本的东西。有人可以解释我会怎样做:

I seem to be missing something basic here. Can someone explain how I would do something like:

dctx.customer.InsertOnSubmit(cust);
dctx.vehicle.UpdateOnSubmit(veh);
dctx.stock.InserOnSubmit (股票);

dctx.customer.InsertOnSubmit(cust);
dctx.vehicle.UpdateOnSubmit(veh);
dctx.stock.InserOnSubmit(stock);

dctx.SubmitChanges(ConflictMode.ContinueOnConflict);

dctx.SubmitChanges(ConflictMode.ContinueOnConflict);

推荐答案

LINQ to SQL执行自动更改跟踪,因此它已经知道您对通过DataContext检索的对象所做的更改。隐含了在SubmitChanges期间更新对象的请求。它还知道您何时创建了对象的新实例并将其与已经跟踪的对象(通过关系属性)相关联,因此在这些情况下您甚至不需要调用InsertOnSubmit。

LINQ to SQL does automatic change tracking, so it is already aware of changes you've made to objects you've retrieved via the DataContext. A request to update the object during SubmitChanges is implied. It also knows when you've created a new instance of an object and associated it with an object that it is already tracking (via a relationship property), so in those cases you don't even need to call InsertOnSubmit. 


这篇关于为什么没有“UpdateOnSubmit”方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆