public CircleGetSummariesResult GetSummaries(CircleGetSummariesCommand command) { // 모든 서클의 목록을 받아옴 var all = circleRepository.FindAll(); // 페이징 처리 var circles = all .Skip((command.Page - 1) * command.Size) .Take(command.Size); var summaries = new List <CircleSummaryData>(); foreach (var circle in circles) { // 각 서클의 서클장에 해당하는 사용자 정보 검색 var owner = userRepository.Find(circle.Owner); summaries.Add(new CircleSummaryData(circle.Id.Value, owner.Name.Value)); } return(new CircleGetSummariesResult(summaries)); }
public CircleGetSummariesResult GetSummaries(CircleGetSummariesCommand command) { // 全件取得して var all = circleRepository.FindAll(); // その後にページング var circles = all .Skip((command.Page - 1) * command.Size) .Take(command.Size); var summaries = new List <CircleSummaryData>(); foreach (var circle in circles) { // サークルのオーナーを改めて検索 var owner = userRepository.Find(circle.Owner); summaries.Add(new CircleSummaryData(circle.Id.Value, owner.Name.Value)); } return(new CircleGetSummariesResult(summaries)); }
public CircleGetSummariesResult GetSummaries(CircleGetSummariesCommand command) { // この段階ではデータを取得しない var all = circleRepository.FindAll(); // ページング処理は条件を付与しているに過ぎないためデータを取得しない var chunk = all .Skip((command.Page - 1) * command.Size) .Take(command.Size); // ここではじめてコレクションが処理されるため、条件に応じてデータ取得がされる var summaries = chunk .Select(x => { var owner = userRepository.Find(x.Owner); return(new CircleSummaryData(x.Id.Value, owner.Name.Value)); }) .ToList(); return(new CircleGetSummariesResult(summaries)); }
public CircleGetSummariesResult GetSummaries(CircleGetSummariesCommand command) { // 아직은 데이터를 받아오지 않았다 var all = circleRepository.FindAll(); // 야기서는 페이징 처리 조건만 부여한 것으로 데이터를 받지는 않았다 var chunk = all .Skip((command.Page - 1) * command.Size) .Take(command.Size); // 이 시점에서 처음으로 컬렉션의 요소에 접근했으므로 조건에 따라 데이터를 받아온다 var summaries = chunk .Select(x => { var owner = userRepository.Find(x.Owner); return(new CircleSummaryData(x.Id.Value, owner.Name.Value)); }) .ToList(); return(new CircleGetSummariesResult(summaries)); }
public CircleGetSummariesResult GetSummaries(CircleGetSummariesCommand command) { var all = circleRepository.FindAll(); var page = command.Page; var size = command.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 CircleGetSummariesResult(summaries)); }
public CircleGetSummariesResult GetSummaries(CircleGetSummariesCommand command) { var all = from circle in context.Circles join owner in context.Users on circle.OwnerId equals owner.Id select new { circle, owner }; var page = command.Page; var size = command.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 CircleGetSummariesResult(summaries)); }
public CircleGetSummariesResult GetSummaries(CircleGetSummariesCommand command) { 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 = command.Page; var size = command.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 CircleGetSummariesResult(summaries)); } } }