0

I want to use chained linq. I am having some trouble with the syntax.

select * from APPLES
inner join BANANAS on APPLES.id = BANANAS.someid

I have:

var result = workspace.GetDataSource<APPLE>().Join(.......)

but I am unsure about what goes into the Join bit. Could someone help me out?

NibblyPig
  • 51,118
  • 72
  • 200
  • 356
  • You've probably read this but I don't know if it would help... http://msdn.microsoft.com/en-us/library/bb311040.aspx – Thomas Schultz May 31 '11 at 15:22
  • My lamda syntax for my edited answer was based upon this: http://stackoverflow.com/questions/2767709/c-joins-where-with-linq-and-lambda – Jeff Machamer May 31 '11 at 15:26

1 Answers1

4

How about:

var result = from a in workspace.GetDataSource<APPLE>()
             from b in workspace.GetDataSource<BANANAS>()
             where a.id == b.someid
             select a;

or if you want to use join notation:

var result = from a in workspace.GetDataSource<APPLE>()
             join b in workspace.GetDataSource<BANANAS>()
             on a.id equals b.someid
             select a;

Note, you can change the select a to a projection of the elements you need from both tables.

Not as familiar with this format, but it would be something like this:

var result = workspace.GetDataSource<APPLE>().Join(workspace.GetDataSource<BANANAS>(),a=>a.id, b=>b.someid,(a,b) => a);
Jeff Machamer
  • 942
  • 4
  • 7