Reputation: 5543
How can I combine following LINQ statments into just one statement
var albums = db.Albums.Include(a => a.Artist).Include(a => a.Genre);
var albumByGenre = from a in albums
where a.GenreId == GenreId
orderby a.AlbumId descending
select a;
List<Album> albumList = albumByGenre.ToList();
Upvotes: 0
Views: 113
Reputation: 23107
Here is combined wersion with function syntax
var albumList = db.Albums.Include(a => a.Artist).Include(a => a.Genre) //1st part
.Where(a=>a.GenreId==GenreId).OrderByDescending(x=>x.AlbumId) //2nd part
.ToList(); //3rd part
You can just chain queries into one big query
Upvotes: 2