开发者

Could I have some help converting inner joins in sql into linq?

开发者 https://www.devze.com 2023-03-09 18:01 出处:网络
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 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 resu开发者_高级运维lt = workspace.GetDataSource<APPLE>().Join(.......)

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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号