问题描述
我正在将我们的 DAL 类库迁移到 .NET 4(从 .NET 3.5).我们经常使用类型化数据集,并且我们经常迭代表:
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;
这不再起作用,因为设计者更改了数据集的代码,以便表不再从 TypedTableBase
派生,而是从 DataTable
派生(并实现非泛型 IEnumerable
).这就是差异显示的内容.因此,该行在编译时属于 object
类型.
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:
在解决方案资源管理器中选择 xsd 文件,然后单击运行自定义工具".设计器文件将使用 TypedTableBase 而不是 DataTable 和 IEnumerable 重新生成.
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.
这篇关于在 .NET 4 中未使用 TypedTableBase 的类型化数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!