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 的类型化数据集


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01