VB.NET中的Linq语法

VB.NET中的Linq语法,vb.net,linq,anonymous-types,Vb.net,Linq,Anonymous Types,我真正想要的是将这两个表选择成一个anon类型,就像Scott Gu的博客中那样:然而,我会满足于这种创建的类型“ActiveLots”。我将两个表连接在一起,并希望能够引用结果集中每个表的列 我似乎没有正确理解语法 Dim pi = From p In dc.Inventories Join i In dc.InventoryItems On p.InventoryItemID _ Equals i.InventoryItemID Where p.L

我真正想要的是将这两个表选择成一个anon类型,就像Scott Gu的博客中那样:然而,我会满足于这种创建的类型“ActiveLots”。我将两个表连接在一起,并希望能够引用结果集中每个表的列

我似乎没有正确理解语法

 Dim pi = From p In dc.Inventories Join i In dc.InventoryItems On p.InventoryItemID _
                     Equals i.InventoryItemID Where p.LotNumber <> "" _
                     Select New ActiveLots LotNumber = p.LotNumber, Quantity = p.Quantity, Item = i.Item, Uom = i.UnitofMeasure, Description = i.Description
Dim pi=从dc.InventoryItemID上的p.InventoryItems的dc.InventoryItems中加入i_
等于i.InventoryItemID,其中p.LotNumber“”_
选择New ActiveLots LotNumber=p.LotNumber,Quantity=p.Quantity,Item=i.Item,Uom=i.UnitofMeasure,Description=i.Description
看一看。我怀疑你想要:

Dim pi = From p In dc.Inventories _
         Join i In dc.InventoryItems
              On p.InventoryItemID Equals i.InventoryItemID _
         Where p.LotNumber <> "" _
         Select New With { .LotNumber = p.LotNumber, .Quantity = p.Quantity, _
                           .Item = i.Item, .Uom = i.UnitofMeasure, _
                           .Description = i.Description }
Dim pi=来自dc库存中的p_
加入dc.InventoryItems
在p.InventoryItemID上等于i.InventoryItemID_
其中p.LotNumber“”_
用{.LotNumber=p.LotNumber、.Quantity=p.Quantity选择New_
.Item=i.Item,.Uom=i.UnitofMeasure_
.Description=i.Description}

这是使用匿名类型-要使用具体类型,您将使用带有{…(其中
ActiveLots
必须有一个无参数构造函数)的
newactivelots是正确的。显然,ActiveLot需要一个空构造函数。感谢您的确认。我们将进行适当的编辑。