在子查询中使用顺序和Distinct的LINQ语句

本文关键字:Distinct LINQ 语句 顺序 查询 | 更新日期: 2023-09-27 18:14:10

嗨,我有以下LINQ查询,我试图排序和选择不同的值。

 var records = (from c in db.pt
                       join y in db.pro on c.id equals y.id
                       where c.id == id
                       select new proj
                           {
                               id = cid,
                               newStructure = new List<team>
                                   {
                                       new teamP
                                           {
                                               t_id = c.p_id,
                                               full_name = c.per.last_name + " ," + c.per.last_name,
                                           }
                                   }
                           }).ToList().OrderBy("full_name").distinct();

在上面关于OrderBy的查询中,我得到了"不能从用法中推断出"的智能错误。尝试显式指定类型参数"请让我知道如何修复这个错误。由于

在子查询中使用顺序和Distinct的LINQ语句

这样做

var records = (from c in db.pt
               join y in db.pro on c.id equals y.id
                  where c.id == id
                         select new proj
                          {
                             id = cid,
                              newStructure = new List<team>
                                {
                                    new teamP
                                       {
                                           t_id = c.p_id,
                                           full_name = c.per.last_name + " ," +                         c.per.last_name,
                                       }
                               }
                       }).distinct().ToList();

添加这一行

records=records.OrderBy(x=>x.fullname == "Full_Name");