【发布时间】:2015-11-15 14:55:51
【问题描述】:
我有一个包含 500K 行的数据表,格式如下;
Int | Decimal | String
我们使用的是单例模式,最终我们的DataTable 需要以List(Of AssetAllocation) 结尾,其中AssetAllocation 是:
Public Class AssetAllocation
Property TpId() As Integer
Property Allocation As List(Of Sector)
End Class
Public Class Sector
Property Description() As String
Property Weighting As Decimal
End Class
我正在使用的 linq;
Private Shared Function LoadAll() As List(Of AssetAllocation)
Dim rtn = New List(Of AssetAllocation)
Using dt = GetRawData()
Dim dist = (From x In dt.AsEnumerable Select x!TP_ID).ToList().Distinct()
rtn.AddRange(From i As Integer In dist
Select New AssetAllocation With {
.TpId = i,
.Allocation = (From b In dt.AsEnumerable
Where b!TP_ID = i Select New Sector With {
.Description = b!DESCRIPTION.ToString(),
.Weighting = b!WEIGHT
}).ToList()})
End Using
Return rtn
End Function
执行 linq 需要很长时间,这是由于内部查询构造了扇区列表。不同的列表包含 80k
这可以改善吗?
【问题讨论】:
标签: c# vb.net linq datatable linq-to-dataset