Lambda表达式仅在不为null和count()时按3个不同字段分组

Lambda表达式仅在不为null和count()时按3个不同字段分组,lambda,linq-to-entities,grouping,Lambda,Linq To Entities,Grouping,这是我的模型 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; } [F

这是我的模型

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; }
}
任何给定行将只具有以下一项:
BookID
ProjectID
CommentID
我想获得通知总数,但我必须按
NotificationType
对它们进行分组,并且这三个ID中的一个,其他两个ID为空。可能有10条评论通知,但其中5条用于回复,5条用于另一个操作——但这应该只有两条通知,而不是10条


如何编写lambda表达式来获取这些计数?

以下操作将起作用

 var notificationCount = db.Notifications
      .GroupBy(x => new { x.CommentID, x.ProjectID, x.BookID, x.NotificationTypeID })
      .Count();
基于