首先匹配LINQ结果

时间:2014-05-06 00:27:53

标签: c# linq

我有以下代码:

var term = "ata";
var list = Cache.GetReferenceList<T>()
             .Where(x => x.AirportCode == term || x.AirportName.Contains(term))
             .Take(5).Select(z => new AirportResult
             {
                 ID = z.AirportId,
                 label = z.AirportCode + " - " + z.AirportName
             })
             .ToList();

如果这给我返回一个标签如下所示的列表:

  1. &#34; ACV - Arcata&#34;
  2. &#34; AMI - Matarami&#34;
  3. &#34; ATA - Anta&#34;
  4. 如何订购列表(使用OrderBy),以便搜索词和AirportCode的匹配位于顶部,然后按AirportCode排序?我追求的结果看起来像这样:

    1. &#34; ATA - Anta&#34;
    2. &#34; ACV - Arcata&#34;
    3. &#34; AMI - Matarami&#34;

1 个答案:

答案 0 :(得分:1)

您可以使用布尔值<{1}}执行此操作:

OrderBy