Typed dataset not using TypedTableBase in .NET 4

I am porting our DAL class library to .NET 4 (from .NET 3.5). We often use typed datasets, and we often repeat tables:

foreach(var row in ds.MyTable) var tmp = row.ID; 

This does not work anymore, since the constructor changes the code of the data set, so that the tables are no longer derived from TypedTableBase<T> , but from DataTable (and implement a non-generic IEnumerable ). What diff shows. Therefore, the string is of type object at compile time.

Does anyone know if this is normal behavior? At the moment, I am doing this as shown below, but I hope there will be a more elegant solution:

 foreach(var row in ds.MyTable.Cast<MyDs.MyRow>()) var tmp = row.ID; 
+4
source share
3 answers

Just stumbled upon it today and was able to fix it by following these steps:

Select the xsd files in the solution explorer and click Run Custom Tool. Designer files will be restored using TypedTableBase instead of DataTable and IEnumerable.

+8
source

The accepted answer is mostly complete, but will not completely resolve the problem.
My question and answer to this question are reproduced here.

Problem:

In short, the problem occurs when the MSDataSetGenerator tool is MSDataSetGenerator , but the System.Data.DataSetExtensions assembly is not yet loaded into the current Visual Studio process.

Decision:

One way to load the assembly is to simply open any XSD file, and THEN to create the developer code.

The following steps should generate the appropriate constructor file:

  • Open any XSD file in the designer view (this will load DataSetExtensions.dll)
  • Right click on XSD and select Run Custom Tool

Here is a complete step-by-step walkthrough of the problem and solution with pictures

Other instances:

This issue was also reported by Microsoft in the following big tickets:

+8
source

All this is correct, but in my case I had to support the source code, which should work with .Net 2.0 and .Net 4.0. My goal was to change as little code as possible.

My solution was to create a partial extension for .Net 4.0 and associate it with the 4.0 application. It looks like this:

 namespace NamespaceOfMyDataSet { public partial class MyDataSet : global::System.Data.DataSet { public partial class MyTypedTable : global::System.Data.TypedTableBase<MyTypedTableRow> { public System.Data.DataRowCollection GetRows() { return this.Rows; } } } } 

It works like a charme !!!

+2
source

Source: https://habr.com/ru/post/1332472/


All Articles