views:

473

answers:

1

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
+1  A: 

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).

Jon Skeet
perfect, thanks!!!
Sara Chipps
Jon, your assumption about "New ActiveLot With..." is correct. Obviously ActiveLot needs an empty constructor.
Meta-Knight
Thanks for the confirmation Meta-Knight. Will edit appropriately.
Jon Skeet