예제 #1
0
        protected virtual void OnExecute(DataSelectContext context, SelectStatement statement)
        {
            //根据生成的脚本创建对应的数据命令
            var command = context.Session.Build(statement);

            context.Result = CreateResults(context.EntityType, context, statement, command, null);
        }
예제 #2
0
                public LazyIterator(DataSelectContext context, SelectStatement statement, IDataReader reader, Action <string, Paging> paginate)
                {
                    var entity = context.Entity;

                    if (!string.IsNullOrEmpty(statement.Alias))
                    {
                        var complex = (IDataEntityComplexProperty)context.Entity.Find(statement.Alias);

                        if (complex.ForeignProperty == null || complex.ForeignProperty.IsSimplex)
                        {
                            entity = complex.Foreign;
                        }
                        else
                        {
                            entity = ((IDataEntityComplexProperty)complex.ForeignProperty).Foreign;
                        }
                    }

                    _context   = context;
                    _statement = statement;
                    _reader    = reader;
                    _paginate  = paginate;
                    _slaves    = GetSlaves(_context, _statement, _reader);
                    _populator = DataEnvironment.Populators.GetProvider(typeof(T)).GetPopulator(entity, typeof(T), _reader);
                }
예제 #3
0
        public void TestCollectionProperties()
        {
            const string NAME = "Security.Role";

            var schema = _accessor.Schema.Parse(NAME, "*, Creator{Modifier{*}}, Users(~CreatedTime){*, Modifier{*}}", typeof(Models.IRoleModel));

            var context = new DataSelectContext(_accessor,
                                                NAME,              //name
                                                schema.EntityType, //entityType
                                                null,              //grouping
                                                Condition.Between("RoleId", 10, 100) | Condition.Like("Modifier.Name", "Popeye*"),
                                                schema,            //schema
                                                null,              //paging
                                                Sorting.Descending("RoleId") + Sorting.Ascending("Creator.Name"));

            var statements = context.Build();

            Assert.NotNull(statements);
            Assert.NotEmpty(statements);

            var command = context.Session.Build(statements.First());

            Assert.NotNull(command);
            Assert.NotNull(command.CommandText);
            Assert.True(command.CommandText.Length > 0);
            Assert.True(command.Parameters.Count > 0);

            System.Diagnostics.Debug.WriteLine(command.CommandText);
        }
예제 #4
0
        public void TestGrouping()
        {
            const string NAME = "Security.User";

            var grouping = Grouping.Group("Status");

            grouping.Aggregates.Count("*");

            var context = new DataSelectContext(_accessor,
                                                NAME,     //name
                                                null,     //entityType
                                                grouping, //grouping
                                                Condition.Equal("UserId", 100) | (Condition.Like("Modifier.Name", "Popeye*") & Condition.GreaterThan("CreatedTime", DateTime.Today)),
                                                null,     //schema
                                                null,     //paging
                                                Sorting.Descending("UserId") + Sorting.Ascending("Creator.Name"));

            var statements = context.Build();

            Assert.NotNull(statements);
            Assert.NotEmpty(statements);

            var command = context.Session.Build(statements.First());

            Assert.NotNull(command);
            Assert.NotNull(command.CommandText);
            Assert.True(command.CommandText.Length > 0);
            Assert.True(command.Parameters.Count > 0);

            System.Diagnostics.Debug.WriteLine(command.CommandText);
        }
예제 #5
0
        public void Test()
        {
            const string NAME = "Security.User";

            var schema = _accessor.Schema.Parse(NAME, "*, Creator{Name, FullName}", typeof(Zongsoft.Security.Membership.IUser));

            var context = new DataSelectContext(_accessor,
                                                NAME,              //name
                                                schema.EntityType, //entityType
                                                null,              //grouping
                                                Condition.Equal("UserId", 100) | (Condition.Like("Modifier.Name", "Popeye*") & Condition.GreaterThan("Status", 2)),
                                                schema,            //schema
                                                null,              //paging
                                                Sorting.Descending("UserId") + Sorting.Ascending("Creator.Name"));

            var statements = context.Build();

            Assert.NotNull(statements);
            Assert.NotEmpty(statements);

            var command = context.Session.Build(statements.First());

            Assert.NotNull(command);
            Assert.NotNull(command.CommandText);
            Assert.True(command.CommandText.Length > 0);
            Assert.True(command.Parameters.Count > 0);

            System.Diagnostics.Debug.WriteLine(command.CommandText);
        }
예제 #6
0
        protected virtual bool OnExecute(DataSelectContext context, SelectStatement statement)
        {
            //根据生成的脚本创建对应的数据命令
            var command = context.Session.Build(statement);

            context.Result = CreateResults(context.ModelType, context, statement, command, null);

            return(false);
        }
예제 #7
0
 private static IEnumerable CreateResults(Type elementType, DataSelectContext context, SelectStatement statement, DbCommand command, Action <string, Paging> paginator)
 {
     return((IEnumerable)System.Activator.CreateInstance(
                typeof(LazyCollection <>).MakeGenericType(elementType),
                new object[]
     {
         context, statement, command, paginator
     }));
 }
예제 #8
0
            public LazyCollection(DataSelectContext context, SelectStatement statement, DbCommand command, Action <string, Paging> paginate)
            {
                _context   = context ?? throw new ArgumentNullException(nameof(context));
                _statement = statement ?? throw new ArgumentNullException(nameof(statement));
                _command   = command ?? throw new ArgumentNullException(nameof(command));

                if (paginate != null)
                {
                    _paginate = paginate;
                }
                else
                {
                    _paginate = (key, paging) => this.OnPaginated(key, paging);
                }
            }