如何将以下LINQ语句合并为一个语句
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();
答案 0 :(得分:2)
这里结合了wersion和函数语法
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
您可以将查询链接到一个大查询