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

时间:2014-07-22 10:20:47

标签: c# linq entity-framework

您好我遵循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的上述查询,我​​得到了intellisence错误“无法根据用法推断出来。请尝试明确指定类型参数” 请让我知道如何解决此错误。谢谢

1 个答案:

答案 0 :(得分:0)

喜欢这样。

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");