मेरे पास एक LINQ क्वेरी है जो मेरे PictureGallery
कक्षा के साथ मेल खाने वाले परिणाम देता है। मैं उन्हें अपने ViewModel
लेकिन im निम्न त्रुटि हो रही में लोड करने की आवश्यकता है:मैं इन LINQ परिणामों को अपने व्यूमोडेल क्लास में कैसे लोड करूं?
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?)
मैं सी # में नहीं बल्कि नया हूँ। मैं अपने "पिक्चर गैलरी" व्यूमडेल क्लास में "परिणाम" कैसे डालूं?
अग्रिम धन्यवाद!
नियंत्रक:
//Test MediaID
var MediaID = 75;
//Query Results
var Results = from g in DB.Galleries
join m in DB.Media on g.GalleryID equals m.GalleryID
where g.GalleryID == GalleryID
orderby m.MediaDate descending, m.MediaID descending
select new { g.GalleryTitle, Media = m };
//Create my viewmodel
var Model = new GalleryViewModel
{
MediaID = MediaID,
PictureGallery = Results, //This line throws the error.
PictureCount = Results.Count()
};
ViewModels:
public class GalleryViewModel
{
public int? MediaID { get; set; }
public IEnumerable<PictureGallery> PictureGallery { get; set; }
public int PictureCount { get; set; }
}
public class PictureGallery
{
public int GalleryID { get; set; }
public string GalleryTitle { get; set; }
public int MediaID { get; set; }
public string MediaTitle { get; set; }
public string MediaDesc { get; set; }
public double Rating { get; set; }
public int Views { get; set; }
}
हाँ कि काम की जांच कर सकते हैं! धन्यवाद – Maddhacker24