【问题标题】:How to get a filtered List?如何获得过滤后的列表?
【发布时间】:2018-05-24 15:37:34
【问题描述】:

这就是场景。我有下一节课:

class A
{ 
    string  attribute1; 
    string  attribute2;
    List<B> attribute3;
}

class B 
{
    string attribute1;
}

我的程序运行一个:

list<Class A>    myList

我想得到,使用linq过滤,一个特定的列表Class A

所以,据我所知,我正在通过以下方式获取列表或列表:

myList.SelectMany(o => o.attribute3.Where(p => p.attribute1 == "test")).ToList()

myList.SelectMany(o => o.attribute3.Select(p => p.attribute1 == "test")).ToList()

有什么线索吗?谢谢小伙伴们。

【问题讨论】:

  • 你想得到什么结果?
  • @HesamFaridmehr。感谢您的答复。我想得到一个过滤列表类。
  • 你想获取所有A中任何B都有测试值的A类吗?
  • 我想得到一个所有 A 类的普通列表,它的属性 3 中有一个值 == "test"(即 B 类列表)。 @HesamFaridmehr

标签: c# asp.net linq entity-framework-6 linq-to-entities


【解决方案1】:

只要运行:

myList.Where(o => o.attribute3.Any(p => p.attribute1 == "test")).ToList()

【讨论】:

  • 是的,完成:)
  • 酷。再次感谢:)
猜你喜欢
  • 2011-07-23
  • 2012-09-21
  • 1970-01-01
  • 1970-01-01
  • 2013-02-10
  • 2018-09-06
  • 2015-09-18
  • 1970-01-01
  • 2014-03-05
相关资源
最近更新 更多