我必须搜索用户可以输入Order Number
或keyword
的字段。关键字需要在MemberOrderLineItem
ItemName
值中进行搜索。
现在我正在为这样的订单号做。
memberOrderInformationList = memberOrderInformationList
.Where(x => x.OrderNumber.Contains(searchString))
.OrderByDescending(x => x.OrderDate)
.ToList();
但是如何包含MemberOrderLineItem ItemName
值?
public class MemberOrderInformation
{
public string OrderNumber { get; set; }
public DateTime? OrderDate { get; set; }
...
public List<MemberOrderLineItem> LineItems { get; set; }
public MemberOrderInformation()
{
LineItems = new List<MemberOrderLineItem>();
}
}
[Serializable]
public class MemberOrderLineItem
{
public string OrderNumber { get; set; }
public int OrderLineNumber { get; set; }
public string ItemName { get; set; }
public string Status { get; set; }
...
...
}
答案 0 :(得分:2)
试试这个
memberOrderInformationList = memberOrderInformationList.Where(x=>x.OrderNumber.Contains(searchString)
|| x.LineItems.any(p => p.ItemName.Contains(searchString))
).OrderByDescending(x => x.OrderDate).ToList();
答案 1 :(得分:0)
如果我正确理解了这个问题,你可以试试
memberOrderInformationList =
memberOrderInformationList.Where(x=>x.OrderNumber.Contains(searchString)
|| x.LineItems.FirstOrDefault(l => l.ItemName.Contains(searchString)) != null)
.OrderByDescending(x => x.OrderDate).ToList();
编辑:看看其他答案,使用.Any()
反对.FirstOrDefault
是一个更清晰的选择,尽管两者都应该同样有效。
答案 2 :(得分:0)
你可以试试这个:
#!/usr/bin/perl
use warnings;
use strict;
my @chr;
my $input;
open ($input, "$ARGV[0]") || die;
while (<$input>) {
my @r = split(/\t/);
my $snps = $r[0];
my $pval = $r[1];
my $pmid = $r[2];
my $chrpos = $r[3];
my $chrid = $r[4];
for ($chrid) {
push (@chr, $chrid);
}
}
close $input;
答案 3 :(得分:-1)
memberOrderInformationList = memberOrderInformationList
.Where(x => x.OrderNumber.Contains(searchString))
.OrderByDescending(x => x.OrderDate)
.Where(x=>x.LineItems.Any(x=>x.ItemName == "hej"))
.ToList();