public override JoinQueryResult Visit(RootQueryExpression exp) { Type type = exp.ElementType; TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(type); string explicitTableName = exp.ExplicitTable; DbTable dbTable = typeDescriptor.Table; if (explicitTableName != null) { dbTable = new DbTable(explicitTableName, dbTable.Schema); } string alias = this._queryModel.GenerateUniqueTableAlias(dbTable.Name); DbTableSegment tableSeg = CreateTableSegment(dbTable, alias, exp.Lock); DbTable aliasTable = new DbTable(alias); ComplexObjectModel model = typeDescriptor.GenObjectModel(aliasTable); //TODO 解析 on 条件表达式 var scopeParameters = this._scopeParameters.Clone(this._conditionExpression.Parameters.Last(), model); DbExpression condition = GeneralExpressionParser.Parse(this._conditionExpression, scopeParameters, this._queryModel.ScopeTables); DbJoinTableExpression joinTable = new DbJoinTableExpression(this._joinType.AsDbJoinType(), tableSeg, condition); JoinQueryResult result = new JoinQueryResult(); result.ResultModel = model; result.JoinTable = joinTable; return(result); }
public override JoinQueryResult Visit(RootQueryExpression exp) { IQueryState queryState = new RootQueryState(exp, this._scopeParameters, this._queryModel.ScopeTables, a => { return(this._queryModel.GenerateUniqueTableAlias(a)); }); JoinQueryResult result = queryState.ToJoinQueryResult(this._joinType, this._conditionExpression, this._scopeParameters, this._queryModel.ScopeTables, null); return(result); }
static RootQueryExpression CreateRootQueryExpression(DbContext dbContext, string explicitTable, LockType @lock) { Type entityType = typeof(T); RootQueryExpression ret = new RootQueryExpression(entityType, explicitTable, @lock); List <LambdaExpression> filters = dbContext.QueryFilters.FindValue(entityType); if (filters != null) { ret.ContextFilters.AddRange(filters); } return(ret); }
public override JoinQueryResult Visit(RootQueryExpression exp) { Type type = exp.ElementType; TypeDescriptor typeDescriptor = TypeDescriptor.GetDescriptor(type); string explicitTableName = exp.ExplicitTable; DbTable dbTable = typeDescriptor.Table; if (explicitTableName != null) { dbTable = new DbTable(explicitTableName, dbTable.Schema); } string alias = this._resultElement.GenerateUniqueTableAlias(dbTable.Name); DbTableSegment tableSeg = CreateTableExpression(dbTable, alias); MappingObjectExpression moe = new MappingObjectExpression(typeDescriptor.EntityType.GetConstructor(Type.EmptyTypes)); DbTable table = new DbTable(alias); foreach (MappingMemberDescriptor item in typeDescriptor.MappingMemberDescriptors.Values) { DbColumnAccessExpression columnAccessExpression = new DbColumnAccessExpression(table, item.Column); moe.AddMemberExpression(item.MemberInfo, columnAccessExpression); if (item.IsPrimaryKey) { moe.PrimaryKey = columnAccessExpression; } } //TODO 解析 on 条件表达式 DbExpression condition = null; List <IMappingObjectExpression> moeList = new List <IMappingObjectExpression>(this._moeList.Count + 1); moeList.AddRange(this._moeList); moeList.Add(moe); condition = GeneralExpressionVisitor.ParseLambda(this._conditionExpression, moeList); DbJoinTableExpression joinTable = new DbJoinTableExpression(this._joinType, tableSeg, condition); JoinQueryResult result = new JoinQueryResult(); result.MappingObjectExpression = moe; result.JoinTable = joinTable; return(result); }
public override JoinQueryResult Visit(RootQueryExpression exp) { Type type = exp.ElementType; TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(type); string explicitTableName = exp.ExplicitTable; DbTable dbTable = typeDescriptor.Table; if (explicitTableName != null) { dbTable = new DbTable(explicitTableName, dbTable.Schema); } string alias = this._resultElement.GenerateUniqueTableAlias(dbTable.Name); DbTableSegment tableSeg = CreateTableSegment(dbTable, alias, exp.Lock); MappingObjectExpression moe = new MappingObjectExpression(typeDescriptor.Definition.Type.GetConstructor(Type.EmptyTypes)); DbTable table = new DbTable(alias); foreach (PropertyDescriptor item in typeDescriptor.PropertyDescriptors) { DbColumnAccessExpression columnAccessExpression = new DbColumnAccessExpression(table, item.Column); moe.AddMappingMemberExpression(item.Property, columnAccessExpression); if (item.IsPrimaryKey) { moe.PrimaryKey = columnAccessExpression; } } //TODO 解析 on 条件表达式 var scopeParameters = this._scopeParameters.Clone(this._conditionExpression.Parameters.Last(), moe); DbExpression condition = GeneralExpressionParser.Parse(this._conditionExpression, scopeParameters, this._resultElement.ScopeTables); DbJoinTableExpression joinTable = new DbJoinTableExpression(this._joinType.AsDbJoinType(), tableSeg, condition); JoinQueryResult result = new JoinQueryResult(); result.MappingObjectExpression = moe; result.JoinTable = joinTable; return(result); }
static QueryModel CreateQueryModel(RootQueryExpression rootQueryExp, ScopeParameterDictionary scopeParameters, StringSet scopeTables, Func <string, string> tableAliasGenerator) { Type entityType = rootQueryExp.ElementType; if (entityType.IsAbstract || entityType.IsInterface) { throw new ArgumentException("The type of input can not be abstract class or interface."); } QueryModel queryModel = new QueryModel(scopeParameters, scopeTables); TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(entityType); DbTable dbTable = typeDescriptor.GenDbTable(rootQueryExp.ExplicitTable); string alias = null; if (tableAliasGenerator != null) { alias = tableAliasGenerator(dbTable.Name); } else { alias = queryModel.GenerateUniqueTableAlias(dbTable.Name); } queryModel.FromTable = CreateRootTable(dbTable, alias, rootQueryExp.Lock); DbTable aliasTable = new DbTable(alias); ComplexObjectModel model = typeDescriptor.GenObjectModel(aliasTable); model.DependentTable = queryModel.FromTable; queryModel.ResultModel = model; ParseFilters(queryModel, typeDescriptor.Definition.Filters, rootQueryExp.ContextFilters); return(queryModel); }
public override IQueryState Visit(RootQueryExpression exp) { IQueryState queryState = new RootQueryState(exp.ElementType, exp.ExplicitTable); return(queryState); }
public override IQueryState Visit(RootQueryExpression exp) { IQueryState queryState = new RootQueryState(exp.ElementType, exp.ExplicitTable, this._scopeParameters, this._scopeTables); return(queryState); }
public override IQueryState Visit(RootQueryExpression exp) { var queryState = new RootQueryState(exp.ElementType); return(queryState); }
public RootQueryState(RootQueryExpression rootQueryExp, ScopeParameterDictionary scopeParameters, StringSet scopeTables, Func <string, string> tableAliasGenerator) : base(CreateQueryModel(rootQueryExp, scopeParameters, scopeTables, tableAliasGenerator)) { this._rootQueryExp = rootQueryExp; }
public RootQueryState(RootQueryExpression rootQueryExp, ScopeParameterDictionary scopeParameters, StringSet scopeTables) : this(rootQueryExp, scopeParameters, scopeTables, null) { }