我有两个表,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