I am trying to filter my dataset before I do join in Linq to Entities but I could not find the way to do it. My current linq query is that makes left joins is :
from m in Products
join f in FileFolders on m.ProductCode equals f.Name into list1
from l1 in list1.DefaultIfEmpty()
join p in Files on l1.FileFolderID equals p.FileFolderID into list2
// I want something like p.Name == "Test" here
from l2 in list2.DefaultIfEmpty()
join b in BaseReferenceFile on l2.BaseReferenceFileID equals b.BaseReferenceFileID into list3
from l3 in list3.DefaultIfEmpty()
select new
{
//select some stuff here
};
I want to filter Files collection such that only the files with name “Test” are joined with l1.
I have tried filtering on l2 with l2.Name == "Test" but it is not working. It generates a weird query with an inner join and a left join.
How can I do that?
1 Answer