Intersecting with LINQ on single column
I have 2 queries.
var suppliers =
from u in db.Users
join s in db.Suppliers
on u.SupplierID equals s.supplierID
select u;
var AreaServiced =
from a in db.Areas_Serviceds
where a.Area.AreaName == AreasServiced
where a.Area.State == StateServiced
select a;
and I want to to intersect them to get all the supplier开发者_如何学JAVA details. So they would just be intersecting on supplierID.
I cant use suppliers = suppliers.intersect(AreaServiced)
because suppliers and areasserviced do not have the same columns.
I currently dont have it in a single statemnet because I dont ALWAYS want htem to intersect (if the user doesnt care about area serviced then i will jsut display the suppleirs without caring where they service)
so later on i can do something like If (!customerCaresAboutAreaServiced) { intersect two tables }
otherwsie i would ignore second table.
Have you tried a Linq join between the two queries? Something like
var intersection =
from su in suppliers
join areas in AreaServiced
on su.SupplierID equals areas.SupplierID
精彩评论