コード例 #1
0
        public void ShouldWhenOrderByWithMapperAndGiveNameLengthDescAndNameAsc()
        {
            var mapper = new ObjectMapper <User, UserDto>();

            mapper.Append(p => p.TAge, p => p.Age);
            mapper.Append(p => p.TId, p => p.Id);
            mapper.Append(p => p.TName, p => p.Name);
            mapper.Append(p => p.TNameLength, p => p.Name.Length);
            var orderInfo = OrderInfo.Parse("TNameLength.desc(),TName");
            var query     = CreateTestUsers().DoOrderBy(orderInfo, mapper);

            JoinIds(query).Should().Be("004,001,003,002");
        }
コード例 #2
0
            private string FilterDtoStudents(string filterExpressionForDto)
            {
                var filter        = FilterInfo.Parse(filterExpressionForDto);
                var studentMapper = new ObjectMapper <Student, StudentDto>();

                studentMapper.Append(p => p.TName, p => p.Name);
                studentMapper.Append(p => p.TAge, p => p.Age);
                studentMapper.Append(p => p.TId, p => p.Id);
                studentMapper.Append(p => p.THeight, p => (decimal?)p.Height);
                studentMapper.Append(p => p.TAddress, p => p.Address);

                var scoreMapper = new ObjectMapper <ScoreRecord, ScoreDto>();

                scoreMapper.Append(p => p.TClassName, p => p.ClassName);
                scoreMapper.Append(p => p.TScore, p => p.Score);
                scoreMapper.Append(p => p.TExam, p => p.Exam as IExam);
                studentMapper.AppendCollection(p => p.TScores, p => p.Scores, scoreMapper);

                var ids = Students.AsQueryable().DoFilter(filter)
                          .Select(p => p.Id);

                return(string.Join(",", ids));
            }
コード例 #3
0
            private string FilterDtoStudents(string filterExpressionForDto)
            {
                var filter        = FilterInfo.Parse(filterExpressionForDto);
                var studentMapper = new ObjectMapper <Student, StudentDto>();

                studentMapper.Append(p => p.TName, p => p.Name);
                studentMapper.Append(p => p.TAge, p => p.Age);
                studentMapper.Append(p => p.TId, p => p.Id);
                studentMapper.Append(p => p.THeight, p => (decimal?)p.Height);
                studentMapper.Append(p => p.TAddress, p => p.Address);

                var scoreMapper = new ObjectMapper <ScoreRecord, ScoreDto>();

                scoreMapper.Append(p => p.TClassName, p => p.ClassName);
                scoreMapper.Append(p => p.TScore, p => p.Score);
                scoreMapper.Append(p => p.TExam, p => p.Exam as IExam);
                studentMapper.AppendCollection(p => p.TScores, p => p.Scores, scoreMapper);

                var ids = dataContext1.Students.DoFilter(filter, studentMapper).OrderBy(p => p.Id)
                          .Select(p => p.Id);

                Console.WriteLine(ids.ToQueryString());
                return(string.Join(",", ids));
            }
コード例 #4
0
ファイル: ObjectMapperTest.cs プロジェクト: obpt123/ys.knife
        public void Test()
        {
            var mapper = new ObjectMapper <C1, C2>();

            mapper.Append(p => p.Name, p => p.Nm + p.Nm)
            .Append(p => p.Age, p => (DateTimeOffset.Now.Year - p.Birthday.Year));
            var source = new C1()
            {
                Nm = "zhangsan", Birthday = DateTimeOffset.Now.AddYears(-10), Address = "xian"
            };
            var target = source.MapOne(mapper);

            target.Should().NotBeNull()
            .And.BeEquivalentTo(new C2()
            {
                Name = "zhangsanzhangsan", Age = 10, Address = "xian"
            });
        }