Typed Dataset not using TypedTableBase in .NET 4(在 .NET 4 中未使用 TypedTableBase 的类型化数据集)
问题描述
我正在将我们的 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 的类型化数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 .NET 4 中未使用 TypedTableBase 的类型化数据集
基础教程推荐
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 将数据集转换为列表 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 如果条件可以为空 2022-01-01
- 从 C# 控制相机设备 2022-01-01
