C# Lambda 多个条件,子列表
想知道以下内容是否可行,但我仍在了解 lambda 表达式。
GetAll(x => x.Username.ToUpper().Contains(SEARCH)
&& x.AddressList.Type_ID == 98.ToList();
这段代码的问题在于“Address”是一个列表。本质上,我们希望在 1) 对 UserName 执行搜索和 2) 匹配子列表的属性后返回 List。
从语义上讲,上面的代码不起作用,因为“Type_ID”不可用作选择,因为 AddressList 是一个列表,而不是单个实体。
这能实现吗?
Would like to know if the following is possible, still getting my head around lambda expressions.
GetAll(x => x.Username.ToUpper().Contains(SEARCH)
&& x.AddressList.Type_ID == 98.ToList();
The trouble with this code is that "Address" is a List. Essentially we would like to return List after 1) performing a search against UserName and 2) matching a property of a child list.
Semantically the code above does not work as 'Type_ID' is not available as a selection due to the fact that AddressList is a List, not a single entity.
Can this be accomplished?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的意思是类似的东西吗?
Do you mean something like?
有一些对列表进行操作的扩展方法,但仍然不清楚您想要做什么。您想要的结果是 AddressList 中的任意项的 Type_ID 为 98 吗?如果是这样,请使用 Any 函数。如果列表中的所有地址都必须具有该类型 ID,则使用“全部”。这是一些示例代码:
输出是:
There are extension methods that operate on lists, but it's still not clear what you want to do. Do you want results where any item in AddressList has a Type_ID of 98? If so, use the Any function. If all addresses in the list must have that type ID than use All. Here's some sample code:
The output is: