/// <summary> /// Instancie o objeto e clona /// </summary> /// <param name="pTableQuery">Objeto table query</param> public TableQuery(TableQuery pTableQuery) : this() { DbName = pTableQuery.DbName; TableName = pTableQuery.TableName; FieldName = pTableQuery.FieldName; Alias = pTableQuery.Alias; SchemaTable = pTableQuery.SchemaTable; Top = pTableQuery.Top; Distinct = pTableQuery.Distinct; Fields = new TableAdapterFieldCollection(pTableQuery.Fields); foreach (OrderBy myItem in pTableQuery.OrderBy) { OrderBy.Add(new OrderBy(myItem)); } pTableQuery.Wheres.ForEach( w => Wheres.Add(new WhereCollection(w))); if (pTableQuery.Joins != null) { pTableQuery.Joins.ForEach( j => Joins.Add(new Join(j))); } if (pTableQuery.Union != eUnionType.eutNone) { pTableQuery.InternalQuery.ForEach( c => InternalQuery.Add(new TableQuery(c))); } }
void InitFromBase(SqlTable baseTable) { if (Alias == null) { Alias = baseTable.Alias; } if (Database == null) { Database = baseTable.Database; } if (Owner == null) { Owner = baseTable.Owner; } if (PhysicalName == null) { PhysicalName = baseTable.PhysicalName; } foreach (var field in baseTable.Fields.Values) { if (!Fields.ContainsKey(field.Name)) { Fields.Add(new SqlField(field)); } } foreach (var join in baseTable.Joins) { if (Joins.FirstOrDefault(j => j.TableName == join.TableName) == null) { Joins.Add(join); } } }
void InitFromBase(SqlTable baseTable) { if (_alias == null) { _alias = baseTable._alias; } if (_database == null) { _database = baseTable._database; } if (_owner == null) { _owner = baseTable._owner; } if (_physicalName == null) { _physicalName = baseTable._physicalName; } foreach (var field in baseTable.Fields.Values) { if (!Fields.ContainsKey(field.Name)) { Fields.Add(new SqlField(field)); } } foreach (var join in baseTable.Joins) { if (Joins.Find(j => j.TableName == join.TableName) == null) { Joins.Add(join); } } }
public void AddJoin(SqlSubQueryJoin joinSpec, string childAlias, string parentAlias) { joinSpec.ParentSubQuery = GetSubQuery(joinSpec.ParentTableName, parentAlias); joinSpec.ChildSubQuery = GetSubQuery(joinSpec.ChildTableName, childAlias); Joins.Add(joinSpec); }
public IJoin <TEntity> Join(Expression <Func <object> > joinAlias, JoinType joinType = JoinType.Inner) { var join = new Join <TEntity>(this, joinType, joinAlias); Joins.Add(join); return(join); }
public SqlTable([JetBrains.Annotations.NotNull] MappingSchema mappingSchema, ExtensionList extensions, string name) : this() { if (mappingSchema == null) { throw new ArgumentNullException("mappingSchema"); } if (extensions == null) { throw new ArgumentNullException("extensions"); } if (name == null) { throw new ArgumentNullException("name"); } var te = extensions[name]; if (te == TypeExtension.Null) { throw new ArgumentException(string.Format("Table '{0}' not found.", name)); } Name = te.Name; Alias = (string)te.Attributes["Alias"].Value; Database = (string)te.Attributes["Database"].Value; Owner = (string)te.Attributes["Owner"].Value; PhysicalName = (string)te.Attributes["PhysicalName"].Value ?? te.Name; foreach (var me in te.Members.Values) { Fields.Add(new SqlField( (Type)me["Type"].Value, me.Name, (string)me["MapField"].Value ?? (string)me["PhysicalName"].Value, (bool?)me["Nullable"].Value ?? false, -1, (bool?)me["Identity"].Value == true ? new IdentityAttribute() : null, null)); } foreach (var ae in te.Attributes["Join"]) { Joins.Add(new Join(ae)); } var baseExtension = (string)te.Attributes["BaseExtension"].Value; if (!string.IsNullOrEmpty(baseExtension)) { InitFromBase(new SqlTable(mappingSchema, extensions, baseExtension)); } var baseTypeName = (string)te.Attributes["BaseType"].Value; if (!string.IsNullOrEmpty(baseTypeName)) { InitFromBase(new SqlTable(mappingSchema, Type.GetType(baseTypeName, true, true))); } }
public SelectStatement Join(string parentColumn, SelectStatement selectStatement, string alias, string column) { GetJoinAndColumnDef(parentColumn, (parentJoin, parentColumnDef) => GetSelectColumn(column, selectStatement, selectColumn => { Join join = new Join(parentJoin, parentColumnDef, selectColumn.ColumnDef, alias, selectStatement); Joins.Add(@join); })); return(this); }
public SqlBuilder AddJoin(SqlSourceJoinType type, string source) { if (Joins == null) { Joins = new List <SqlSourceJoin>(); } Joins.Add(new SqlSourceJoin(type, source)); return(this); }
ToDBCommand Join(string table, Action <ConditionBuilder> where, Join.JoinType joinType) { ConditionBuilder whereBuilder = new ConditionBuilder(); where (whereBuilder); Joins.Add(new Join { Table = new TableItem { Item = table }, On = whereBuilder, TypeOfJoin = joinType }); return(this); }
/// <summary> /// Creates a new Join clause statement fot the current query object /// </summary> protected JoinClause Join(JoinType type, string joinTable) { // Add clause to list of joins var table = new TableIndentifier(joinTable, null); var clause = new JoinClause(this, type, table); Joins.Add(clause); // Add the table to the tables list, and then reset the LastInsertIndex Tables.Add(table); NextAliasIndex = 0; return(clause); }
protected override Expression VisitMember(MemberExpression node) { _propertyDepth++; var result = base.VisitMember(node); _currentFieldMetadata = _currentEntityMetadata.Fields.FirstOrDefault(x => x.Name == node.Member.Name || x.Name == $"FK_{node.Member.Name}_ID"); if (_currentFieldMetadata == null) { throw new InvalidOperationException("The property is not part of entity."); } if (_currentFieldMetadata.IsComplexFieldType && !_currentFieldMetadata.Enum && _propertyDepth > 1) { _currentEntityMetadata = EntityMetadataResolver.EntityMetadata.FirstOrDefault(x => x.Name == _currentFieldMetadata.FieldType); _propertyPath = string.IsNullOrWhiteSpace(_propertyPath) ? node.Member.Name : $"{_propertyPath}.{node.Member.Name}"; TableJoin tableJoin; //check if we already have a join if (_propertyJoinMapping.ContainsKey(_propertyPath)) { tableJoin = _propertyJoinMapping[_propertyPath]; } else { tableJoin = new TableJoin(_currentEntityMetadata.Table, GetTableAlias(), _currentAlias, _currentFieldMetadata.Name, !_currentFieldMetadata.Mandatory); _propertyJoinMapping.Add(_propertyPath, tableJoin); Joins.Add(tableJoin); } _currentAlias = tableJoin.Alias; _propertyDepth--; } else { if (!_isOrdering) { EmitSql($"{_currentAlias}.{_currentFieldMetadata.Name}"); } else { _orderProperty = _currentFieldMetadata.Name; } _propertyPath = string.Empty; _propertyDepth = 0; } return(result); }
///<inheritdoc/> public IJoinQuery <SelectQuery> RightOuterJoin(Table table, IWhereClause clause) { if (table == null) { throw new ArgumentNullException(nameof(table), $"{nameof(table)} cannot be null"); } if (clause == null) { throw new ArgumentNullException(nameof(clause), $"{nameof(clause)} cannot be null"); } Joins.Add(new RightOuterJoin(table, clause)); return(this); }
public SelectStatement Join(string foreignKeyColumn, string alias) { /* * usage: .CreateSelect("core.Product", "p").Join("p.ProductTypeId", "pt") * * joins the foreign key p.ProductTypeId to the referenced object on its primary key */ GetJoinAndColumnDef(foreignKeyColumn, (parentJoin, parentColumnDef) => { ObjectDef objectDef = parentColumnDef.ReferencedObject; ColumnDef columnDef = objectDef.PrimayKeyColumn; Join join = new Join(parentJoin, parentColumnDef, columnDef, alias); Joins.Add(join); }); return(this); }
public SelectStatement Join(string parentAlias, string primaryObject, string alias) { /* * usage: .CreateSelect("core.ProductType", "pt").Join("pt", "core.Product", "p") * * joins the primary key of pt.ProductTypeId to the foreigh key of core.Product that references core.ProductType */ Join parentJoin = Joins.Single(item => item.Alias == parentAlias); ObjectDef objectDef = _builder.ObjectDefs.Single(item => item.FullName == primaryObject); ColumnDef columnDef = _builder.ColumnDefs.Single(item => item.ObjectDef == objectDef && item.ReferencedObject == parentJoin.ObjectDef); Join join = new Join(parentJoin, parentJoin.ObjectDef.PrimayKeyColumn, columnDef, alias); Joins.Add(join); return(this); }
public SqlTable(MappingSchema mappingSchema, SqlTable table) : this(mappingSchema) { _alias = table._alias; _database = table._database; _owner = table._owner; _name = table._name; _physicalName = table._physicalName; _objectType = table._objectType; foreach (var field in table.Fields.Values) { Fields.Add(new SqlField(field)); } foreach (var join in table.Joins) { Joins.Add(join.Clone()); } }
public Join CreateJoin(string targetTable, string sourceColumn, string targetColumn, string targetTableAlias = null, JoinTypes type = JoinTypes.Inner, bool isEqui = true) { if (targetTable == null) { throw new ArgumentNullException(nameof(targetTable)); } if (sourceColumn == null) { throw new ArgumentNullException(nameof(sourceColumn)); } if (targetColumn == null) { throw new ArgumentNullException(nameof(targetColumn)); } Join join = new Join(targetTable, sourceColumn, targetColumn, targetTableAlias, type, true); Joins.Add(join); return(join); }
public SqlTable(SqlTable table) : this() { Alias = table.Alias; Database = table.Database; Owner = table.Owner; Name = table.Name; PhysicalName = table.PhysicalName; ObjectType = table.ObjectType; _sequenceAttributes = table._sequenceAttributes; foreach (var field in table.Fields.Values) { Fields.Add(new SqlField(field)); } foreach (var join in table.Joins) { Joins.Add(join.Clone()); } SqlTableType = table.SqlTableType; TableArguments = table.TableArguments; }
public void CalculateDuration(DateTime start, DateTime end) { if (Joins.Count == 0) { AtStart = true; Joins.Add(start); Joins.Sort(); } if (Leaves.Count == 0) { AtEnd = true; Leaves.Add(end); Leaves.Sort(); } if (IsLeaveFirst()) { AtStart = true; Joins.Add(start); Joins.Sort(); } if (IsJoinLast()) { AtEnd = true; Leaves.Add(end); Leaves.Sort(); } Joins.Sort(); Leaves.Sort(); Duration = MemberRaidDuration.Calculate(Joins, Leaves, AtStart, AtEnd); }
public void AddJoin(SqlTable tbl, SqlColumn col1, SqlColumn col2, SqlJoinType type = SqlJoinType.Left) { Joins.Add(new SqlJoin(From, tbl, type, col1, col2)); }
public FromClause RightJoin(string table_source, string alias, ICondition search_condition) { Joins.Add(new JoinClause(new SqlLiteral(table_source), alias, search_condition, JoinType.Right)); return(this); }
public FromClause RightJoin(ISqlExpression table_source, string alias, ICondition search_condition) { Joins.Add(new JoinClause(table_source, alias, search_condition, JoinType.Right)); return(this); }
private void AddNewJoin() { var join = new JoinViewModel(RecordType, RecordService, ApplicationController, AddNewJoin, j => Joins.Remove(j), OnConditionSelectedChanged); Joins.Add(join); }
public void AdicionarRelacionamento(string relacionamento) { Joins.Add(relacionamento); }
public SelectQuery CrossJoin(string tableName) { Joins.Add($"{Query.Cross} {Query.ColumnSyntax(tableName)}"); return(this); }
protected override Expression VisitMethodCall(MethodCallExpression node) { var expression = node.Arguments[0]; if (expression.NodeType == ExpressionType.Call) { var expression5 = expression as MethodCallExpression; if (expression5.Method.Name == "NoLock") { expression = expression5.Arguments[0]; } } var key = "<>" + Path.GetRandomFileName(); if (expression.NodeType == ExpressionType.Call) { var expression1 = (MethodCallExpression)expression; var visitor2 = new JoinExpressionVisitor(Context); visitor2.Visit(expression); if (node.Method.Name == "SelectMany") { SelectExpression = node.Arguments[2]; key = ((LambdaExpression)((UnaryExpression)node.Arguments[2]).Operand).Parameters[1].Name; var joins = visitor2.Joins; var pair = joins.LastOrDefault(); joins.Remove(pair.Key); Joins.Add(key, pair.Value); return(node); } } SelectExpression = node.Arguments[4]; var expression2 = node.Arguments[1]; if (expression2.NodeType == ExpressionType.Call) { var expression6 = (MethodCallExpression)expression2; if (expression6.Method.Name != "NoLock") { throw new Exception(); } expression2 = expression6.Arguments[0]; } if (expression2.NodeType != ExpressionType.Constant) { throw new Exception(); } var expression3 = node.Arguments[2]; var expression4 = node.Arguments[3]; var visitor = new MemberExpressionVisitor(Context); visitor.Visit(expression3); if (visitor.Token.Type != TokenType.Column) { throw new Exception(); } var join = new Join { Left = visitor.Token.Column }; visitor = new MemberExpressionVisitor(Context); visitor.Visit(expression4); join.Right = visitor.Token.Column; var name = node.Method.Name; if (name != "Join") { if (name != "GroupJoin") { throw new Exception(); } } else { join.JoinType = JoinType.Inner; var expression8 = (LambdaExpression)((UnaryExpression)node.Arguments[4]).Operand; Joins.Add(key, join); return(node); } join.JoinType = JoinType.Left; var expression7 = (LambdaExpression)((UnaryExpression)node.Arguments[4]).Operand; Joins.Add(key, join); return(node); }
public FromClause LeftJoin(string table_name, ICondition search_condition) { Joins.Add(new JoinClause(new SqlLiteral(table_name), table_name, search_condition, JoinType.Left)); return(this); }
public SelectQuery FullJoin(string tableName, string columnFrom, string columnJoin) { Joins.Add($"{Query.Full} {Query.ColumnSyntax(tableName)} {Query.On} {Query.ColumnSyntax(columnFrom)} = {Query.ColumnSyntax(columnJoin)}"); return(this); }
public Query Join(JoinBase join) { Joins.Add(join); QueryElements.Add(join); return(this); }