如何组合多个LINQ表达式



如何将以下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();

版本与函数语法的结合

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

你可以把查询串成一个大查询

相关内容

  • 没有找到相关文章

最新更新