类型化的DataSet不是在.NET 4中使用TypedTableBase是在、类型、TypedTableBase、DataSet

2023-09-07 13:11:19 作者:放过你放过自己

我移植了DAL类库.NET 4中(从.NET 3.5)。我们使用类型化数据集很多时候,我们经常遍历表:

 的foreach(VAR行ds.MyTable)VAR TMP = row.ID;
 

这不工作了,因为设计者改变数据集的code,使表不从 TypedTableBase&LT得出; T> 了,但是从数据表(和实施非通用的IEnumerable )。这就是在差异显示。因此,该行是类型对象在编译时。

有谁知道这是通常的行为吗?目前,我正在做如下图所示的样子,但我希望有一个更好的解决方案:

 的foreach(VAR行ds.MyTable.Cast< MyDs.MyRow>())VAR TMP = row.ID;
 

解决方案

只是遇到了这个今天才得以通过执行以下操作进行修正:

asp.net如何从SqlDataAdapter DataSet中获取字段

选择在Solution Explorer中的XSD文件,然后单击运行自定义工具。设计者文件将使用TypedTableBase,而不是数据表和IEnumerable再生。

I'm migrating our DAL class library to .NET 4 (from .NET 3.5). We're using typed datasets quite often, and we often iterate over tables:

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

This does not work anymore, as the designer changes the dataset's code so that tables do not derive from TypedTableBase<T> anymore, but from DataTable (and implement the non-generic IEnumerable). That's what the diff shows. Therefore, the row is of type object at compile-time.

Does anybody know if this is the usual behavior? At the moment, I'm doing it the way shown below, but I hope there's a more elegant solution:

foreach(var row in ds.MyTable.Cast<MyDs.MyRow>()) var tmp = row.ID;

解决方案

Just ran into this today and was able to correct it by doing the following:

Select the xsd files in the solution explorer and click "Run Custom Tool". The designer files will be regenerated using TypedTableBase instead of DataTable and IEnumerable.