Как мне перевести это в LINQ?
Скажем, у меня есть родительская таблица (скажем, клиенты) и дочерние (адреса).
Я хочу вернуть всех родителей, у которых есть адреса вКалифорния, и только адрес Калифорнии.(но я хочу сделать это в LINQ и получить граф объектов Entity)
Вот старомодный способ:
SELECT c.blah, a.blah
FROM Customer c
INNER JOIN Address a on c.CustomerId = a.CustomerId
where a.State = 'CA'
Проблема, с которой я столкнулся в LINQ, заключается в том, что янужен граф объектов конкретных типов сущностей (и он не может быть загружен ленивым.
Вот что я пробовал до сих пор:
Редактировать: добавление экземпляра контекста по запросу
// this one doesn't filter the addresses -- I get the right customers, but I get all of their addresses, and not just the CA address object.
var ctx = new CustomersContext() // dbContext -- using EF 4.1
from c in ctx.Customer.Include(c => c.Addresses)
where c.Addresses.Any(a => a.State == "CA")
select c
// this one seems to work, but the Addresses collection on Customers is always null
var ctx = new CustomersContext() // dbContext -- using EF 4.1
from c in ctx.Customer.Include(c => c.Addresses)
from a in c.Addresses
where a.State == "CA"
select c;
Есть идеи?