我将使用LINQ查询将DataTable
对象中的数据转换为自定义POCO对象的简单IEnumerable
。
我的LINQ查询如下:
Dim dtMessages As DataTable
'...dtMessages is instantiated ByRef in a helper data access routine... '
Dim qry = From dr As DataRow In dtMessages.Rows
Select New OutboxMsg With {
.ComputerID = dr(dcComputerID),
.MessageData = dr(dcMessageData),
.OutBoxID = dr(dcOutBoxID),
.OutBoxReceivedID = dr(dcOutBoxReceivedID),
.TrxDate = dr(dcTrxDate)
}
然而,在
dr As DataRow
下编译器会抛出一个警告信息,内容为:“Option Strict On禁止将'Object'隐式转换为'System.Data.DataRow'。” 我为什么会收到这个错误消息,并且我需要做些什么来修复它呢?我原本认为dtMessages.Rows
返回的是类型为DataRow
的集合。这不正确吗?
Option Strict
!开玩笑的,开玩笑的。 - Marc