I am trying to use where condition with IQueryable<T>
Join approach but find no resources to give me clue how how to filter records based on child table field.
e.g Normal query that I want to execute via IQueryable<T>
Linq Statement:
Select
m.*
from
vsk_media as m
inner join
vsk_media_album as v
on
m.id=v.mediaid
where
v.albumid=47
Here is my code which works well without where statement:
IQueryable<vsk_media> Query = entities.vsk_media;
Query.Join(entities.vsk_media_albums
, c => c.id
, cm => cm.mediaid
, (c, cm) => new { c, cm });
Now how to add where condition to match with child table vsk_media_albums
(where v.albumid=47) in above IQueryable Statement.
I tried my best to find solution but not found any good resource in web. I am not interested in normal Linq Statement.
You could try this using extension methods:
var query = entities.vsk_media
.Join(entities.vsk_media_album,
m => m.id,
v => v.mediaid,
(m, v) => new { m, v })
.Where(x => x.v.albumid == 47)
.Select(x => x.m);
var list = query.ToList();
Or using the linq structure:
var query = from m in entities.vsk_media
join v in entities.vsk_media_album on m.id equals v.mediaid
where v.albumid = 47
select m;
var list = query.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With