初学者 Linq 语法和 EF4 问题
问题
通过以下 linq 代码片段,我得到了一个客户端列表,其地址已按规范过滤,但返回的实体的形式不是我所期望的。
数据为 1 个客户端有 2 个地址和 1 个客户端有 1 个地址。
该查询返回 3 行客户端,每行有 1 个地址
- Client 1 =>地址 1
- 客户端 1 =>地址2
客户端2 =>地址3
var query = 来自 context.Clients.Where(specification.SatisfiedBy()).Include("ClientAddresses") 中的 t1 在 context.ClientAddresses.Where(spec.SatisfiedBy()) 中加入 t2 t1.ClientKey 等于 t2.ClientKey 选择t1;
我的期望更像是一个只有两个客户端的列表,一个客户端包含两个地址的集合,一个客户端包含一个地址的集合。
- 客户端1 =>地址 1 / 地址 2
- 客户端 2 =>地址3
我缺少什么???
谢谢!
Question
With the following linq code snip I get a list of clients with address filtered by the specifications but the form of the entities returned is not what i had expected.
The data is 1 client with 2 addresses and 1 client with 1 address.
The query returns 3 rows of clients each with 1 address
- Client 1 => Address1
- Client 1 => Address2
Client 2 => Address3
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;
My expectation was a little more like a list with only two clients in it, one client with a collection of two addresses and one client with a collection of one address.
- Client 1 => Address1 / Address2
- Client 2 => Address3
What am I missing???
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过类似的事情吗:
query = query.Distinct();
?您可能需要揭示规范的编写方式以提供更多数据。
例如,我不明白为什么您的查询不是这样的:
更新
看看这是否有效。不确定 EF 支持其中多少。它与您原来的查询非常相似
did you try something like:
query = query.Distinct();
?You might need to reveal how the specifications are written to give more data.
For example, I don't see why your query is not something like:
Update
See if this works. Not sure how much of that is supported by EF. It's very similar to your oriignal query