本文介绍了类型化的DataSet不是在.NET 4中使用TypedTableBase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植了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;
 

解决方案

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

选择在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.

这篇关于类型化的DataSet不是在.NET 4中使用TypedTableBase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 03:49