Sara Chipps
Sara Chipps

Reputation: 9372

Linq syntax in VB.NET

What I really want is to select these two tables in to an anon type like in Scott Gu's blog: here However, I would settle for this created type "ActiveLots" I am joining two tables together and want to be able to reference columns from each in my result set.

I don't seem to be getting the syntax correctly.

 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

Upvotes: 1

Views: 2509

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499950

Have a look at Daniel Moth's blog entry. I suspect you want:

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 }

That's using an anonymous type - to use a concrete type, you'd use New ActiveLots With { ... (where ActiveLots has to have a parameterless constructor).

Upvotes: 2

Related Questions