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 的类型化数据集
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
