I am using EF 4 for my asp.net MVC project, and I have a query to
return all photos in my repository as follows:
public IQueryable<Photo> ListAllPhotos()
{
var photoList = (from albumPhoto in entities.AlbumPhotoes
join photo in entities.Photos on
albumPhoto.PhotoId equals photo.PhotoId
join photoAlbum in entities.PhotoAlbums on
albumPhoto.PhotoAlbumId equals photoAlbum.PhotoAlbumId
join photoCategory in
entities.PhotoCategories on photo.PhotoCategoryId equals
photoCategory.PhotoCategoryId
select new Photo
{
photo.PhotoId,
photo.PhotoTitle,
photo.PhotoDesc,
photo.PhotoCaption,
photo.PhotoFileUrlThumb,
photo.PhotoViewCount,
photo.CreationDate,
photoCategory.PhotoCategoryName,
photoAlbum.PhotoAlbumName
});
return photoList; //error here,not compile!
}
I need to return the query results which includes multiple records so
that they can be displayed in a view (through a viewmodel). but as
shown in above code, the return statement has an error saying that "
Cannot implicitly convert type 'System.Linq.IQueryable' to
'System.Linq.IQuerayable<Model.PhotoGallery.Photo>'.
How to fix that? Please help
More general question is how to return the query results in
IQuerayble.