protected virtual void OnExecute(DataSelectContext context, SelectStatement statement) { //根据生成的脚本创建对应的数据命令 var command = context.Session.Build(statement); context.Result = CreateResults(context.EntityType, context, statement, command, null); }
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); }
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); }
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); }
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); }
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); }
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 })); }
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); } }