コード例 #1
0
        public async Task <IEnumerable <TopSellingAlbumViewModel> > Handle(TopSellingAlbumsRequest request)
        {
//            return await _dbContext.Database.Connection
//                .QueryAsync<TopSellingAlbumViewModel>(@"SELECT TOP (5)
//    [Project1].[AlbumId] AS [Id],
//    [Project1].[Title] AS [Title],
//    [Project1].[AlbumArtUrl] AS [ArtUrl]
//    FROM ( SELECT
//        [Extent1].[AlbumId] AS [AlbumId],
//        [Extent1].[Title] AS [Title],
//        [Extent1].[AlbumArtUrl] AS [AlbumArtUrl],
//        (SELECT
//            COUNT(1) AS [A1]
//            FROM [dbo].[OrderDetails] AS [Extent2]
//            WHERE [Extent1].[AlbumId] = [Extent2].[AlbumId]) AS [C1]
//        FROM [dbo].[Albums] AS [Extent1]
//    )  AS [Project1]
//    ORDER BY [Project1].[C1] DESC");

            return(await _dbContext.Albums
                   .OrderByDescending(a => a.OrderDetails.Count())
                   .Take(request.MaximunResults)
                   .Project()
                   .To <TopSellingAlbumViewModel>()
                   .ToListAsync());
        }
コード例 #2
0
        public async Task <ActionResult> Index()
        {
            var request = new TopSellingAlbumsRequest(MaximunResults);

            var topSellingAlbums = await _mediator.SendAsync(request);

            return(View(topSellingAlbums));
        }