最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net mvc - Linq c# is creating 2 rows when the Linq should just return one row with multiple rows inside the Select new { } -

programmeradmin3浏览0评论

I have this expression:

from comps in ctx.TblControls
join reviews in ctx.TblReviews on comps.Id equals reviews.ControlId
join tags in ctx.TblTags on comps.TagId equals tags.Id
join framework in ctx.TblFrameworks on comps.FrameworkId equals framework.Id
where comps.Guid == guid
select new
{
      ratingTotal = ((ctx.TblReviews.Where(x => x.Rating == 5).Count() * 5) + (ctx.TblReviews.Where(x => x.Rating == 4).Count() * 4) + (ctx.TblReviews.Where(x => x.Rating == 3).Count() * 3) + (ctx.TblReviews.Where(x => x.Rating == 2).Count() * 2) + (ctx.TblReviews.Where(x => x.Rating == 1).Count() * 1)),
      ratingValue = ctx.TblReviews.Where(x => x.Rating == 5).Count() + ctx.TblReviews.Where(x => x.Rating == 4).Count() + ctx.TblReviews.Where(x => x.Rating == 3).Count() + ctx.TblReviews.Where(x => x.Rating == 2).Count() + ctx.TblReviews.Where(x => x.Rating == 1).Count(),
      reviews,       
      tags,
      framework,
      comps
}

return View(new { componentData = componentData.FirstOrDefault() });

and the result is that the expression is returning 2 rows because the "reviews" has two rows returning but i need the Select new {} to return one row with the data inside, where "reviews" has a count of 2.

I hope i explained this right, if i have not, let me know and ill include pictures.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论