在数据源中删除DataAdapter.Fill方法()行为的行 [英] DataAdapter.Fill() behavior for row deleted at the data source
问题描述
我使用了数据集
/ 数据表
/ DataAdapter的
架构,数据库和我的模型对象,它们有自己的支持(他们不是一个DataRow支持)之间进行调停。我有一个 DataAdapter的
与 AcceptChangesDuringFill =假
, AcceptChangesDuringUpdate =假
和 FillLoadOption = OverwriteChanges
。这是我的理解 DataAdapter的
在这些条件下的模型:
I'm using the DataSet
/DataTable
/DataAdapter
architecture to mediate between the database and my model objects, which have their own backing (they aren't backed by a DataRow). I've got a DataAdapter
with AcceptChangesDuringFill = False
, AcceptChangesDuringUpdate = False
, and FillLoadOption = OverwriteChanges
. Here's my understanding of the DataAdapter
model under these conditions:
-
DataRowState.Added
将导致的InsertCommand
烧成 -
DataRowState.Modified
将导致更新命令
烧成 -
DataRowState.Deleted
将导致的DeleteCommand
烧成
DataRowState.Added
will result in theInsertCommand
firingDataRowState.Modified
will result in theUpdateCommand
firingDataRowState.Deleted
will result in theDeleteCommand
firing
- 在任何行返回的结果集的主键对应于
数据表中现有的行
将用于更新该行,而该行的状态会一直变DataRowState.Modified
,即使返回的行等同于当前行的 的 - 在任何行返回的结果集的主键不对应于任何现有的行会被用来创建一个新的行,该行的状态会变成
DataRowState.Added
- 在任何行中的
数据表
不对应于行中返回的结果集将保持在DataRowState.Unchanged
- Any row in the returned result set whose primary key corresponds to an existing row in the
DataTable
will be used to update that row, and that row's state will always becomeDataRowState.Modified
, even if the returned row is identical to the current row - Any row in the returned result set whose primary key doesn't correspond to any existing row will be used to create a new row, and that row's state will become
DataRowState.Added
- Any row in the
DataTable
that doesn't correspond to a row in the returned result set will stay atDataRowState.Unchanged
由于我是正确的这一心理模型,假设我要使用填写()
的通知数据源中删除的行。此外,假设参数的的SelectCommand
不返回整个表。我猜,我有两个选择:
Given that I'm correct with this mental model, suppose I want to use Fill()
to notice deleted rows in the data source. Also, suppose that the parameters of the SelectCommand
don't return the entire table. I'm guessing that I have two options:
- 找到所有应该已经被更新的行
填写()
,但仍DataRowState.Unchanged
(依赖于我的未经检验的斜体的假设之上)。这些行已在数据源被删除。 - 清除所有相关行
数据表
在填写()
;没有再次出现的任何行已经在数据源中被删除。这失去的DataRowState.Added
的区别和DataRowState.Modified
是preserved与第一种方法。
- Find all the rows that should've been updated by the
Fill()
but are stillDataRowState.Unchanged
(relies on my untested italicized assumption above). These rows have been deleted at the data source. - Clear all relevant rows from the
DataTable
before theFill()
; any row that doesn't show up again has been deleted at the data source. This loses the distinction betweenDataRowState.Added
andDataRowState.Modified
that is preserved with the first method.
所以,我的问题:
- 是
DataAdapter的
正确的,受到的属性值我注意到在上面? 我的上述模型
- 哪些选项应该我去找到删除的行?我想preFER第一位的,但是这依赖于我的假设,所有返回的行会被设置为
DataRowState.Modified
,即使该行是相同的;是一个安全的假设? - 我要对这个完全错误的?
- Is my above model of the
DataAdapter
correct, subject to the property values I noted at the top? - Which option should I go with to find deleted rows? I'd prefer the first one, but that relies on my assumption that all returned rows will be set to
DataRowState.Modified
even if the row is identical; is that a safe assumption? - Am I going about this all wrong?
推荐答案
原来,我的假设是错误的,如果由返回的行的SelectCommand
是完全一样的一排已经在数据表
,该行仍标记为 DataRowState.Unchanged
。因此,正确的方法是去除行数据表
在调用填写()
,并确定一排的命运一套新的 DataRowState.Added
行比较行前清单。
Turns out that my assumption is erroneous—if a row returned by the SelectCommand
is exactly the same as a row already in the DataTable
, that row remains marked as DataRowState.Unchanged
. So the proper procedure is removing rows from the DataTable
before calling Fill()
, and determining the fate of a row by comparing the new set of DataRowState.Added
rows to the former list of rows.
这篇关于在数据源中删除DataAdapter.Fill方法()行为的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!