开发者

EF 1.0 flattening a left join query

开发者 https://www.devze.com 2023-03-18 05:57 出处:网络
I\'m trying to execute a linq to entites query in(Visual Studio3.5 /EF 1.0) for 3 entities with the following relationships:

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 => * xcCIFToCSID

Previously 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
                }; 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号