【问题标题】:How do I access Original and Modified versions of strongly typed DataRow?如何访问强类型 DataRow 的原始版本和修改版本?
【发布时间】:2011-10-10 14:50:18
【问题描述】:

我正在编写代码以在我的 winforms over datasets 应用程序中模拟工作单元模式。

我有以下几点:

foreach (EomApp1.Formss.Accounting.Data.AccountingView.AccountingViewRow 
                in accountingView.GetChanges(DataRowState.Modified).Tables[0].Rows)
            {
                 // break point -> immediate window

立即窗口:

modified.Tables[0].Rows[0]["Cost/Unit", DataRowVersion.Original]
1
modified.Tables[0].Rows[0]["Cost/Unit", DataRowVersion.Current]
0

有没有办法使用强类型数据集访问上述信息? (在我的示例中,accountingView ,但我不知道如何在不使用列的字符串名称的情况下获取更改的 DataRowVersion 对象。

【问题讨论】:

    标签: c# dataset strongly-typed-dataset unit-of-work


    【解决方案1】:

    据我所知没有。
    要摆脱魔术字符串,您可以这样做

    modified.Tables[0].Rows[0][Tables[0].CostUnitColumn.ColumnName, DataRowVersion.Current]
    

    【讨论】:

      【解决方案2】:

      System.Data.DataSetExtensions 程序集中的DataRowExtensions.Field 扩展方法是否为您解决了这个问题?注意DataColumnDataRowVersion的参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-06
        相关资源
        最近更新 更多