我有两个表,picture
并pictureratings
在我的数据库中。
public partial class picture
{
public int idpicture { get; set; }
public int iduser { get; set; }
public string picTitle { get; set; }
public string picFilename { get; set; }
public System.DateTime pictime { get; set; }
public int nuditylevel { get; set; }
public int fakeslevel { get; set; }
// This property will hold the total accumulated/summed
// up rating of a picture
public int totalrating { get; set; }
}
public partial class pictureratings
{
public int idrating { get; set; }
public int idpictures { get; set; }
public int iduser { get; set; }
public System.DateTime iddatetime { get; set; }
public int iduserrateddby { get; set; }
public int rating { get; set; }
}
对于每个评级,pictureratings
将创建一个新行。我想pictureratings
按图片ID对表格进行分组,然后计算喜欢人数。我想picture
在totalrating
属性表中显示喜欢的人。
因此,根据我到目前为止的研究,我能够编写此代码
var total = from p in db.picturedetails
join l in db.picturelikes on p.idpictures equals l.idpictures
group l by l.idpictures into g
select new
{
IdUserPic = g.First().iduser,
IdPictures = g.First().idpictures,
totalrating = g.Count()
}
我正在使用Web API返回查询总数。所以这才是我的问题:如何展示picture
样特性iduser
,picTitle
,picFilename
,pictime
,nuditylevel
和fakeslevel
?我做对了吗?我该怎么办?
您可以将一个匿名班分组。这样,您可以访问p&l属性。
看起来像这样:
var total = from p in db.picturedetails
join l in db.picturelikes on p.idpictures equals l.idpictures
group new {p,l} by l.idpictures into g
select new
{
IdUserPic = g.First().p.iduser,
IdPictures = g.First().p.nuditylevel,
totalrating = g.Count()
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句