8,497
社区成员
发帖
与我相关
我的任务
分享
var images = from img in db.Images
where img.UserId == user.UserId
group img by img.GalleryId into g
select new {
GalleryId = g.Key,
Title = g.OrderBy( t => t.ImageId ).Take(1).ToString(),
Description = g.OrderBy(t => t.ImageId).Take(1).ToString(),
Path = g.OrderBy(t => t.ImageId).Take(1).ToString(),
ImageId = Convert.ToInt32(g.OrderBy( t=> t.ImageId).Take(1))
};
怎么遍历 images, 想给Photo 类赋值, 运行时报错LINQ to Entities 不识别方法“System.String ToString()”,,该怎么办?
foreach (var img in imgages)
{
int k = i % 3;
if( k ==0 ){
list1.Add(new Photo { Description = img.Description, ImageId = img.ImageId, GalleryId = img.GalleryId,
Path = img.Path, column = k, PhotoNum = photoNum, Title = img.Title});
}
/// <summary>
/// 相册模型
/// </summary>
public class Photo
{
[Key]
public int ImageId { get; set; }
public int PhotoNum { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Path { get; set; }
public int UserId { get; set; }
public int column { get; set; }
public int GalleryId { get; set; }
}
var images = from img in db.Images
where img.UserId == user.UserId
group img by img.GalleryId into g
let x=g.OrderBy(t => t.ImageId ).Take(1)
select new {
GalleryId = g.Key,
Title = x.Title,
Description =x.Description,
Path = x.Path,
ImageId =x.ImageId
};