Search code examples
c#datasetstrongly-typed-datasetunit-of-work

How do I access Original and Modified versions of strongly typed DataRow?


I'm writing code to emulate a unit of work pattern in my winforms over datasets application.

I have the following:

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

immediate window:

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

Is there any way to access the above information using strongly typed datasets? (in my example, accountingView is, but I don't know how to get at the changed DataRowVersion objects without using the string names of the columns.


Solution

  • as far as I know there is none.
    To get rid of the magic strings you could do

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