Here’s the model I have.
public class Notification
{
public int NotificationID { get; set; }
public bool ReadStatus { get; set; }
public DateTime DateCreated { get; set; }
[ForeignKey("User"), Column(Order=0)]
public int UserID { get; set; }
[ForeignKey("Actor"), Column(Order = 1)]
public int ActorID { get; set; }
[ForeignKey("NotificationType")]
public int NotificationTypeID { get; set; }
//public int ObjectID { get; set; }
[ForeignKey("Comment")]
public int? CommentID { get; set; }
[ForeignKey("Project")]
public int? ProjectID { get; set; }
[ForeignKey("Book")]
public int? BookID { get; set; }
public Comment Comment { get; set; }
public Book Book { get; set; }
public Project Project { get; set; }
public NotificationType NotificationType { get; set; }
public User User { get; set; }
public User Actor { get; set; }
}
Any given row will only have ONE of the following: BookID, ProjectID, CommentID
I want to get a count of total notifications BUT I have to group them by NotificationType AND one of the those three IDs, the other two IDs are null. There may be 10 comment notifications, but 5 of those are for a reply, and 5 are for another action – that should only be TWO notifications though, not 10.
How would I write a lambda expression to get these counts?
The following will work.
Based on This Answer