【问题标题】:using distinct with lambda expression with date对带有日期的 lambda 表达式使用 distinct
【发布时间】:2013-12-28 17:19:25
【问题描述】:

我想获取行数,但是当日期不重复时 举例

id name  date
1  ali   1/1/2014
2  hoda  1/1/2014
3  samir 2/1/2014

正确的计数是 2,因为我想计算一次日期 我正在使用实体框架和 lambda 表达式 我正在使用下面的课程

public class GroupAttend
{
   [Key]
   public int AttendID { get; set; }
   public int GroupID { get; set; }
   public int StudentID { get; set; }
   public int InstructorID { get; set; }
   public int TimeID { get; set; }
   public DateTime DateAdded { get; set; }
   public int LevelID { get; set; }
   public bool? AttendStatue { get; set; }
   public DateTime DateUpdated { get; set; }
   public bool DelFlag { get; set; }
   public DateTime? DelDate { get; set; }
   public Guid UserAddID { get; set; }
   public Guid userEditID { get; set; }
   public Guid? UserDelID { get; set; }

}

谢谢

【问题讨论】:

    标签: entity-framework


    【解决方案1】:
    int count = context.Table.Select(x => x.DateTimeProperty).Distinct().Count();
    

    【讨论】:

    • 是的,谢谢,但不起作用,因为我想添加条件 &&x.groupid==groupidParameter &&x.levelid==LevelIDParameter
    • 是什么阻止你这样做?
    • 是的,我得到的是使用 var count=uof.GroupAttends.List(g=>g.GroupID==groupID&&g.LevelID==LevelID).Select(d=>d.DateAdded).Distinct( )。数数();返回计数;我现在试试
    • 您不知道 LINQ 是如何工作的以及如何使用它,是吗?你应该阅读一些教程。否则你不仅看不懂我的答案,而且你自己也写不出下一个。
    • 不,我知道我在做什么,但是尝试时出错,谢谢你的代码是正确的
    猜你喜欢
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 1970-01-01
    相关资源
    最近更新 更多