コード例 #1
0
        public CircleGetSummariesOutputData Handle(CircleGetSummariesInputData inputData)
        {
            var all = circleRepository.FindAll();

            var page = inputData.Page;
            var size = inputData.Size;

            var chunk = all
                        .Skip((page - 1) * size)
                        .Take(size);

            var summaries = chunk.Select(x =>
            {
                var owner = userRepository.Find(x.Owner);
                return(new CircleSummaryData(x.Id.Value, owner.Name.Value));
            })
                            .ToList();

            return(new CircleGetSummariesOutputData(summaries));
        }
コード例 #2
0
        public CircleGetSummariesOutputData Handle(CircleGetSummariesInputData inputData)
        {
            var all =
                from circle in context.Circles
                join owner in context.Users
                on circle.OwnerId equals owner.Id
                select new { circle, owner };

            var page = inputData.Page;
            var size = inputData.Size;

            var chunk = all
                        .Skip((page - 1) * size)
                        .Take(size);

            var summaries = chunk
                            .Select(x => new CircleSummaryData(x.circle.Id, x.owner.Name))
                            .ToList();

            return(new CircleGetSummariesOutputData(summaries));
        }
コード例 #3
0
        public CircleGetSummariesOutputData Handle(CircleGetSummariesInputData inputData)
        {
            var connection = provider.Connection;

            using (var sqlCommand = connection.CreateCommand())
            {
                sqlCommand.CommandText = @"
 SELECT
   circles.id as circleId,
   users.name as ownerName
 FROM circles
 LEFT OUTER JOIN users
   ON circles.ownerId = users.id
 ORDER BY circles.id
 OFFSET @skip ROWS
 FETCH NEXT @size ROWS ONLY
";
                var page = inputData.Page;
                var size = inputData.Size;
                sqlCommand.Parameters.Add(new SqlParameter("@skip", (page - 1) * size));
                sqlCommand.Parameters.Add(new SqlParameter("@size", size));

                using (var reader = sqlCommand.ExecuteReader())
                {
                    var summaries = new List <CircleSummaryData>();
                    while (reader.Read())
                    {
                        var circleId  = (string)reader["circleId"];
                        var ownerName = (string)reader["ownerName"];
                        var summary   = new CircleSummaryData(circleId, ownerName);
                        summaries.Add(summary);
                    }

                    return(new CircleGetSummariesOutputData(summaries));
                }
            }
        }