I'm trying to execute a linq to entites query in (Visual Studio 3.5 /EF 1.0) for 3 entities with the following relationships:
xcCRMCounterparty开发者_运维问答 * => 0..1 CSIDsInUse
CSIDsInUse 1 => * xcCIFToCSIDPreviously in T SQL I used:
select distinct CIF, xcCIFToCSID.xcCSID, CounterpartyName
from xcCIFToCSID
left join CSIDsInUse
on xcCIFToCSID.idCSID = CSIDsInUse.Id
left join xcCRMCounterparty
on CSIDsInUse.Id = xcCRMCounterparty.IdCSID
order by CounterpartyName
Now with EF I'm tried to flatten the result set as below, but I don't know how to flatten the xcCRMCounterparty item i.e. it's a collection rather than a single field
var query = from cifto in entities.xcCIFToCSIDSet.Include(x => x.CSIDsInUse).Include(x => x.CSIDsInUse.xcCRMCounterparty)
select new
{
cifto.CIF,
cifto.xcCSID,
cifto.CSIDsInUse.xcCRMCounterparty
};
How can I modify my query so that I can generate flattened results?
Try this:
var query = from cifto in entities.xcCIFToCSIDSet
from x in cifto.CSIDsInUse.xcCRMCouterparty
select new
{
cifto.CIF,
cifto.xcCSID,
x.Name
};
精彩评论