locked
using distinct with child and parent 2 classes using lambda expression RRS feed

  • Question

  • User939559474 posted

    i wanna to get count of rows but when not duplicate date and compare the count of rows with "AbsentCount" column in "GroupAttend" class "Group" class and "GroupAttend" class related with relationship

     public  class Group
      {
          [Key]
          public int GroupID { get; set; }
          public string Code { get; set; }
          public string Title { get; set; }
          public string Summury { get; set; }
          public string Details { get; set; }
          public string Place { get; set; }
          public int? AbsentCount { get; set; }
          public string img { get; set; }
          public DateTime? DateAdded { get; set; }
          public Guid UserAddID { get; set; }
          public Guid userEditID { get; set; }
          public int InstructorID { get; set; }
          public int CategoryID { get; set; }
          public int SubCategoryID { get; set; }
          public int CourseID { get; set; }
          public int LevelID { get; set; }
          public DateTime DateUpdated { get; set; }
          public bool DelFlag { get; set; }
          public DateTime? DelDate { get; set; }
          public Guid? UserDelID { get; set; }
          public virtual IList<GroupAttend> GroupAttends { get; set; }
      }
    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; }
     }

    please wanna do this using lambda expression.

    i try this

    var query = context.Groups.Select(d.GroupAttends.Count() ==d.AbsentCount);
    

    where using distinct with (GroupAttends.DateAdded) here



    Wednesday, February 5, 2014 11:52 AM

Answers

  • User-933407369 posted

    hi haitham,

    According to your description, i would suggest you try the way below:

      var query = ctx.Groups.Select(d => d.GroupAttends.Where(o => o.GroupID == d.GroupID)
    .Select(p => p.AttendID).Distinct().Count() == d.AbsentCount);

    Hope it  helps you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 6, 2014 12:55 AM