protected override Expression VisitConstant(ConstantExpression node) { var table = EntityConfigurationManager.GetTable(node.Type.GetGenericArguments()[0]); ExtraObject = table.Name; return(base.VisitConstant(node)); }
private SchemaModel.Table GetTable(Type tableType) { if (ParserUtils.IsAnonymousType(tableType)) { _tableMember = ((MemberExpression)_memberInfos.Pop()).Member; tableType = ((PropertyInfo)_tableMember).PropertyType; return(GetTable(tableType)); } return(EntityConfigurationManager.GetTable(tableType)); }
protected string GetTableAlias(Column column) { if (!string.IsNullOrWhiteSpace(tableName)) { return(tableName); } if (!string.IsNullOrWhiteSpace(column.Table.Alias)) { return(column.Table.Alias); } var name = column.Name; foreach (var join in _context.Joins.Values) { Dictionary <string, SchemaModel.Column> .ValueCollection.Enumerator enumerator2; if (join.Left.Name == name) { return(join.Left.Table.Alias); } if (join.Right.Name == name) { return(join.Right.Table.Alias); } var table = EntityConfigurationManager.GetTable(join.Left.Table.Type); using (enumerator2 = table.Columns.Values.GetEnumerator()) { while (enumerator2.MoveNext()) { if (enumerator2.Current.Name == name) { return(@join.Left.Table.Name == table.Name ? @join.Left.Table.Alias : @join.Right.Table.Alias); } } } table = EntityConfigurationManager.GetTable(join.Right.Table.Type); using (enumerator2 = table.Columns.Values.GetEnumerator()) { while (enumerator2.MoveNext()) { if (enumerator2.Current.Name == name) { return(@join.Left.Table.Name == table.Name ? @join.Left.Table.Alias : @join.Right.Table.Alias); } } } } throw new Exception(); }
private void BuildDeleteSql() { var str = string.Empty; var table = EntityConfigurationManager.GetTable(_context.ElementType); this.tableName = table.Name; var tableName = GetTableName(table); if (_context.Conditions.Any()) { str = BuildWhere(_context.Conditions); } var format = "DELETE FROM {0} {1}"; format = string.Format(format, tableName, str); _result.CommandText = format; }
private void BuildUpdateSql() { var str = string.Empty; var table = EntityConfigurationManager.GetTable(_context.ElementType); var name = string.Empty; var column = table.Columns.FirstOrDefault(x => x.Value.IsKey) .Value; if (column != null) { name = column.PropertyInfo.Name; } this.tableName = table.Name; var tableName = GetTableName(table); if (_context.Conditions.Any()) { str = BuildWhere(_context.Conditions); } var values = new List <string>(); var str4 = string.Empty; foreach (var str6 in _context.UpdateResult.Keys) { if (str6 != name) { str4 = ParserUtils.GenerateAlias(str6); var item = @"[{str6}] = @{str4}"; _result.Parameters.Add(str4, _context.UpdateResult[str6]); values.Add(item); } } var format = "UPDATE {0} SET {1} {2}"; format = string.Format(format, tableName, string.Join(",", values), str); _result.CommandText = format; }
private void ParseEntityType(Type type) { var table = EntityConfigurationManager.GetTable(type); var table2 = new Table { DataBase = table.DataBase, Name = table.Name, Type = table.Type }; foreach (var column in table.Columns.Values) { var item = new Column { Name = column.Name, DataType = column.PropertyInfo.PropertyType, MemberInfo = column.PropertyInfo, Table = table2 }; Columns.Add(item); Context.Columns.Add(column.Name, item); } }