【发布时间】:2011-01-08 01:20:38
【问题描述】:
问题
使用以下 linq 代码片段,我得到了一个客户列表,其地址按规范过滤,但返回的实体形式不是我所期望的。
数据是1个客户端有2个地址和1个客户端有1个地址。
查询返回 3 行客户端,每行有 1 个地址
- 客户端 1 => 地址 1
- 客户端 1 => 地址 2
-
客户端 2 => 地址 3
var query = from t1 in context.Clients.Where(specification.SatisfiedBy()).Include("ClientAddresses") join t2 in context.ClientAddresses.Where(spec.SatisfiedBy()) on t1.ClientKey equals t2.ClientKey select t1;
我的期望更像是一个只有两个客户的列表,一个客户包含两个地址的集合,一个客户包含一个地址的集合。
- 客户端 1 => 地址 1 / 地址 2
- 客户端 2 => 地址 3
我错过了什么???
谢谢!
【问题讨论】:
-
这越来越近了。这将返回 3 个客户端,但地址数量正确。 var query = from t1 in context.Clients.Where(specification.SatisfiedBy()) join t2 in context.ClientAddresses.Where(spec.SatisfiedBy()) on t1.ClientKey 等于 t2.Client.ClientKey into x from t2 in x select t1;