Search code examples
.netvb.netlinq-to-dataset

LINQ to DataSet with strongly typed data after migration from .NET 3.5 to 4.0


I'm in the progress of migrating our projects from .NET 3.5 to .NET 4.0. Previously I used to be able to use statements on typed datasets such as:

dr = myDataSet.SomeTable.FirstOrDefault(Function(x) x.IdSome = targetId)

This however no longer works. I've already tried adding the reference to System.Data.DataSetExtensions and modify the code to use .AsEnumerable() - however, this only yields a DataRow, not a SomeRow (as would be contained within the SomeTable)

dr = myDataSet.SomeTable.AsEnumerable().FirstOrDefault(Function(x) x.IdSome = targetId)

The resulting error is 'IdSome' is not a member of 'System.Data.DataRow' - some other statements fail with an Overload resolution failed due to the same reason.

How can I retain the type safe, non-magic string code in .NET 4.0?


Solution

  • Turns out that the datasets were messed up during the conversion. After regenerating them (opening one in designer, "Run Custom Tool" on all datasets) fixed the inheritance.

    See also: Typed Dataset not using TypedTableBase in .NET 4