c#使用Linq的group by及多表联查

    public void GetData()
    {
        var groupedCustomerList = CustomerList
            .GroupBy(u => u.GroupID)
            .Select(g => new
            {
                GroupId = g.Key,
                Items = g.Select(i => new
                {
                    UserID = i.ID,
                    UserName = string.Concat("User", i.Name),
                    GroupId = i.GroupID
                }).ToList()
            })
.ToList();




        var type3 = from p in db.feedback_info
                    where p.feedbackdiscussid != null
                    && p.feedbacktype == 3
                    group p by p.feedbackdiscussid
        into g
                    select new
                    {
                        count = g.Count(),
                        key = g.Key,
                        id = g.FirstOrDefault().id
                    };



        var type4 = from p in db.feedback_info
                    from r in db.reply_info
                    where p.feedbackdiscussid == r.id
                    && p.feedbackdiscussid != null
                    && p.feedbacktype == 4
                    group r by new { r.replyuserid, p.content } into g
                    select new
                    {
                        count = g.Count(),
                        key = g.Key,
                        id = g.FirstOrDefault().id
                    };

        var query = (from p in db.feedback_info
                     where (p.feedbacktype != 3 && p.feedbacktype != 4)
                     ||
                     (
                     type3.Where(s => s.id == p.id).Count() > 0
                     || type4.Where(s => s.id == p.id).Count() > 0
                     )
                     ||
                     (
                     (p.feedbacktype == 3 || p.feedbacktype == 4) && p.feedbackdiscussid == null
                     )
                     select p).ToList();

发表评论

电子邮件地址不会被公开。 必填项已用*标注