在我的C#項目中遇到了一個錯誤,導致我頭痛。錯誤是:無法隱式轉換類型'System.Linq.IQueryable <AnonymousType#1>'
Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>'
to System.Collections.Generic.IEnumerable<KST.ViewModels.Gallery>'.
這裏是我的LINQ querys:
//Get Single Picture
var PictureResults = (from m in DB.Media where m.MediaID == 450 select m).SingleOrDefault();
//Get Gallery Pictures and Gallery Title
var GalleryResults = from g in DB.Galleries
join m in DB.Media on g.GalleryID equals m.GalleryID into gm
where g.GalleryID == 100
select new { g.GalleryTitle, Media = gm };
這裏是我的ViewModels。下GalleryResults發生
public class GalleryViewModel
{
public Media Media { get; set; }
public IEnumerable<Gallery> Gallery { get; set; }
}
public class Gallery
{
public string GalleryTitle { get; set; }
public int MediaID { get; set; }
public int GalleryID { get; set; }
public string MediaGenre { get; set; }
public string MediaTitle { get; set; }
public string MediaDesc { get; set; }
}
的squigally行錯誤:
//Create my viewmodel
var Model = new GalleryViewModel
{
Media = PictureResults,
Gallery = GalleryResults
};
錯誤信息的哪部分你不明白? – SLaks