/// <summary> /// Initializes a new instance of the <see cref="ReferenceMapping"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="entityChild">Entity child.</param> /// <param name="entityParent">Entity parent.</param> public ReferenceMapping(string name, string entityChild, EntityMapping entityParent) { _Name = name; _EntityChild = entityChild; _EntityParent = entityParent; _Rules = new RuleMappingCollection(); }
public int Add(EntityMapping value) { if (this[value.Type] == null) return base.List.Add(value as object); return 0; }
private int GetIndexOfPrimaryKey(EntityMapping entity, string paramName) { int indexPrimaryKey = 0; for (; indexPrimaryKey < entity.Ids.Count; indexPrimaryKey++) { if (entity.Ids[indexPrimaryKey].Field == paramName) return indexPrimaryKey; } return 0; }
public Hashtable InitializeCompoundUpdateCommand(EntityMapping entity, ArrayList updateCommands) { Hashtable updateCompoundQueryEntries = new Hashtable(); if (entity.Attributes != null) { // Loops through attributes so as to create as many SQL Update Command as Tables foreach (UpdateAttributeCommand a in updateCommands) { AttributeMapping attributeMapping = entity.Attributes[a.Name]; if (attributeMapping == null) throw new SqlMapperException(string.Format("Cannot find the attribute '{0}' of the entity '{1}' in your mapping file", a.Name, entity.Type)); CacheQueryEntry entry = null; if (attributeMapping.Discriminator == null) { // Creates an UpdateCommand for each Table and add the Where clause for the command if (!updateCompoundQueryEntries.Contains(attributeMapping.Table)) { CacheQueryEntry cacheEntry = new CacheQueryEntry(new UpdateCommand(attributeMapping, attributeMapping.Table)); updateCompoundQueryEntries.Add(attributeMapping.Table, cacheEntry); if ((attributeMapping.ParentField == null || attributeMapping.ParentField == string.Empty) && attributeMapping.Table != entity.Table) { attributeMapping.ParentField = entity.IdFields; Parameter param = new Parameter(attributeMapping, "FK_Entity"); cacheEntry.Parameters.Add(param); ((UpdateCommand)cacheEntry.Query).WhereClause.SearchCondition.Add(new BinaryLogicExpression(new Column(attributeMapping, attributeMapping.ParentField), BinaryLogicOperator.Equals, param)); } } entry = (CacheQueryEntry)updateCompoundQueryEntries[attributeMapping.Table]; } else { // Initialization entry = new CacheQueryEntry(new UpdateCommand(attributeMapping, attributeMapping.Table)); // A tag attribute mapping which name = "*", is an implicit generic query (a mapping for all attributes don't describe) // it is differente to a explicit generic mapping (a mapping foreach attribute) entry.IsAttributeGenericQuery = attributeMapping.Name == "*"; updateCompoundQueryEntries.Add(attributeMapping.Table, entry); } UpdateCommand query = (UpdateCommand)entry.Query; ArrayList parameters = entry.Parameters; if (!query.ColumnValueCollection.Contains(attributeMapping.Field)) { Parameter param = new Parameter(attributeMapping, attributeMapping.Field); parameters.Add(param); query.ColumnValueCollection.Add(attributeMapping.Field, param); if (attributeMapping.Discriminator != null) { if (attributeMapping.Name != "*") { query.WhereClause.SearchCondition.Add(new BinaryLogicExpression( new Column(attributeMapping, attributeMapping.Discriminator), BinaryLogicOperator.Equals, new Constant(attributeMapping.DiscriminatorValue == null ? attributeMapping.Name : attributeMapping.DiscriminatorValue, DbType.String))); param = new Parameter(attributeMapping, "FK_Entity"); parameters.Add(param); query.WhereClause.SearchCondition.Add(new BinaryLogicExpression(new Column(attributeMapping, attributeMapping.ParentField), BinaryLogicOperator.Equals, param)); } else { param = new Parameter(attributeMapping, "AttributeDiscriminator"); parameters.Add(param); query.WhereClause.SearchCondition.Add(new BinaryLogicExpression(new Column(attributeMapping, attributeMapping.Discriminator), BinaryLogicOperator.Equals, param)); param = new Parameter(attributeMapping, "FK_Entity"); parameters.Add(param); query.WhereClause.SearchCondition.Add(new BinaryLogicExpression(new Column(attributeMapping, attributeMapping.ParentField), BinaryLogicOperator.Equals, param)); } } if (attributeMapping.ParentField == null && !entry.ContainsParameter("EntityId") && !entry.ContainsParameter("Id0")) { if (entity.Ids.Count == 1) { param = new Parameter(entity.Ids[0], "EntityId"); parameters.Add(param); query.WhereClause.SearchCondition.Add(new BinaryLogicExpression( new Column(entity, entity.IdFields), BinaryLogicOperator.Equals, param)); } else { for (int i = 0; i < entity.Ids.Count; i++) { PrimaryKeyMapping pkId = entity.Ids[i]; param = new Parameter(pkId, string.Concat("Id", i.ToString())); parameters.Add(param); query.WhereClause.SearchCondition.Add(new BinaryLogicExpression( new Column(entity, entity.GetIdField(pkId)), BinaryLogicOperator.Equals, param)); } } } } } } return updateCompoundQueryEntries; }
private Hashtable ProcessUpdateAttributeCommands(EntityMapping e, ArrayList innerCommands) { Hashtable table = new Hashtable(); // if (e.Attributes != null) { foreach (AttributeMapping a in e.Attributes) { table.Add(a, new ArrayList()); } } // foreach (UpdateAttributeCommand cc in innerCommands) { AttributeMapping a = e.Attributes[cc.Name]; if (a != null) { ArrayList list = (ArrayList)table[a]; list.Add(cc); } } return table; }
private string ConvertId(EntityMapping entity, string paramName, string id) { string[] ids = id.Split(SqlMapperProvider.IDSEP); int indexPrimaryKey = GetIndexOfPrimaryKey(entity, paramName); switch (entity.Ids[indexPrimaryKey].Generator.Name) { // Returns the database generated Id instead of the internal one case GeneratorMapping.GeneratorType.native: case GeneratorMapping.GeneratorType.business: case GeneratorMapping.GeneratorType.assigned: if (_NewIds.ContainsKey(id)) { string[] newIds = _NewIds[id].Split(SqlMapperProvider.IDSEP); return newIds[indexPrimaryKey]; } return ids[indexPrimaryKey]; // Returns the internal entity's id case GeneratorMapping.GeneratorType.guid: return ids[indexPrimaryKey]; case GeneratorMapping.GeneratorType.inherited: return ids[indexPrimaryKey]; default: return ids[indexPrimaryKey]; } return ids[indexPrimaryKey]; }
/// <summary> /// Processes the attributes. /// </summary> /// <param name="entityMap">Entity mapping whitch contains the attribute</param> /// <param name="name">Name of the attribute</param> /// <param name="loadAttributes"></param> /// <param name="checkAlias">Indicate if returned column must have an computed alias name or not</param> /// <returns>Return a <see cref="Column"/></returns> public ISQLExpression ProcessAttributes(EntityMapping entityMap, string name, bool loadAttributes, bool checkAlias) { if (name == "Id") { Table currentTable = (Table)tableContext.Peek(); return new Column(entityMap.Ids[0], currentTable.TableAlias, entityMap.GetIdField(entityMap.Ids[0])); } else { // Exception management : attribute mapping AttributeMapping attributeMapping = entityMap.Attributes[name]; //Attempt to get the attribute in the children types if (attributeMapping == null) foreach (Evaluant.Uss.Models.Entity e in _Model.GetTree(entityMap.Type)) { EntityMapping em = _Mapping.Entities[e.Type]; if ((attributeMapping = em.Attributes[name]) != null) break; } //Attempt to get the attribute in the parent types if (attributeMapping == null) { Evaluant.Uss.Models.Entity cur = _Model.GetEntity(entityMap.Type); while (_Model.GetParent(cur) != null) { cur = _Model.GetParent(cur); EntityMapping current = _Mapping.Entities[cur.Type]; if (current.Attributes[name] != null) attributeMapping = current.Attributes[name]; } } if (attributeMapping == null) throw new UniversalStorageException(String.Format("The attribute '{0}' of the entity '{1}' is not defined in your mapping file", name, entityMap.Type)); // If the attribute is contained in entity's table : the current query doesn't change if (attributeMapping.Table == entityMap.Table) { Table currentTable = (Table)tableContext.Peek(); Column c = new Column(attributeMapping, currentTable.TableAlias, attributeMapping.Field); //if (entityMap.Ids[attributeMapping.Field] != null) // c.ColumnName = entityMap.GetIdField(entityMap.Ids[attributeMapping.Field]); if (checkAlias) { string attributeFullName = _Model.GetFullAttributeName(attributeMapping.Name, attributeMapping.ParentEntity.Type); //if (entityMap.Ids[attributeMapping.Field] != null) // attributeFullName = entityMap.GetIdFieldAs(entityMap.Ids[attributeMapping.Field]); //c.ColumnName = (_AliasColumnMapping.Contains(attributeFullName)) ? _AliasColumnMapping[attributeFullName].ToString() : ""; if (_AliasColumnMapping.Contains(attributeFullName)) c.ColumnName = _AliasColumnMapping[attributeFullName].ToString(); } return c; } // Else : create a new select query else { // Get the current context Table currentTable = (Table)tableContext.Pop(); SelectStatement mainQuery = (SelectStatement)queryContext.Pop(); // Create a new query SelectStatement currentQuery = new SelectStatement(attributeMapping); Table attributeTable = new TableSource(attributeMapping, attributeMapping.Table, CreateUniqueAttributeAlias()); string atrbId = attributeMapping.Table == null || attributeMapping.Table == entityMap.Table ? entityMap.GetIdField(entityMap.Ids[0]) : attributeMapping.ParentField; if (loadAttributes) { return this.ProcessAttributesWithLoadAttribute(mainQuery, currentQuery, currentTable, entityMap, attributeTable, attributeMapping, atrbId); } else { if (_IsFirstAttribute) { _IsFirstAttribute = false; // if current table is a JoinedTable : // from clause = mainQuery INNER JOIN attributeTable if (currentTable.GetType() == typeof(JoinedTable)) { JoinedTable lastJoinTable = new JoinedTable(mainQuery, loadAttributes ? TypeJoinedTable.LeftOuter : TypeJoinedTable.Inner, attributeTable); lastJoinTable.TableAlias = mainQuery.TableAlias; BinaryLogicExpression onCondition = new BinaryLogicExpression( new Column(entityMap.Ids[0], mainQuery.TableAlias, entityMap.GetIdField(entityMap.Ids[0])), BinaryLogicOperator.Equals, new Column(attributeMapping, attributeTable.TableAlias, atrbId)); if (mainQuery.WhereClause.SearchCondition.Count != 0) { foreach (ILogicExpression expression in mainQuery.WhereClause.SearchCondition) { onCondition = new BinaryLogicExpression(onCondition, BinaryLogicOperator.And, expression); } } lastJoinTable.SearchConditions.Add(new BinaryLogicExpression( new Column(entityMap.Ids[0], mainQuery.TableAlias, entityMap.GetIdField(entityMap.Ids[0])), BinaryLogicOperator.Equals, new Column(entityMap.Ids[0], attributeTable.TableAlias, atrbId))); currentQuery.TableAlias = mainQuery.TableAlias; currentQuery.FromClause.Add(lastJoinTable); currentQuery.WhereClause.SearchCondition.Add(new BinaryLogicExpression( new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Discriminator), BinaryLogicOperator.Equals, new Constant(name, DbType.AnsiString))); tableContext.Push(lastJoinTable); queryContext.Push(currentQuery); return new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Field); } // else // from clause = currentTable INNER JOIN attributeTable else { JoinedTable joinTable = new JoinedTable(currentTable, loadAttributes ? TypeJoinedTable.LeftOuter : TypeJoinedTable.Inner, attributeTable); joinTable.SearchConditions.Add(new BinaryLogicExpression( new Column(entityMap.Ids[0], currentTable.TableAlias, entityMap.GetIdField(entityMap.Ids[0])), BinaryLogicOperator.Equals, new Column(attributeMapping, attributeTable.TableAlias, atrbId))); currentQuery.TableAlias = CreateUniqueTableAlias(); currentQuery.FromClause.Add(joinTable); currentQuery.WhereClause.SearchCondition = mainQuery.WhereClause.SearchCondition; tableContext.Push(joinTable); } } else { Table rightTable = ((JoinedTable)currentTable).RigthTable; JoinedTable joinTable = new JoinedTable(attributeTable, TypeJoinedTable.Inner, rightTable); joinTable.SearchConditions.Add(new BinaryLogicExpression( new Column(attributeMapping, rightTable.TableAlias, atrbId), BinaryLogicOperator.Equals, new Column(attributeMapping, attributeTable.TableAlias, atrbId))); ((JoinedTable)currentTable).RigthTable = joinTable; currentQuery.SelectList.Add(new Column(entityMap.Ids[0], currentTable.TableAlias, entityMap.GetIdField(entityMap.Ids[0]))); currentQuery.TableAlias = currentTable.TableAlias; currentQuery.FromClause.Add(currentTable); tableContext.Push(currentTable); } queryContext.Push(currentQuery); return new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Field); } } } }
public ISQLExpression ProcessAttributes(EntityMapping entityMap, string name, bool loadAttributes) { return ProcessAttributes(entityMap, name, loadAttributes, false); }
public void Remove(EntityMapping value) { base.List.Remove((object)value); }
public static string GetParentIdAlias(EntityMapping entity, string field) { string alias = "ParentId"; if (entity.Ids.Count == 1) return alias; for (int i = 0; i < entity.Ids.Count; i++) { if (entity.Ids[i].Field == field) return alias + i.ToString(); } return alias; }
/// <summary> /// Process an attribute like following : /// Person[Brother.Kind.Name = 'nice'] /// </summary> /// <returns>The column corresponding to the required attribute, i.e. : Name</returns> public ISQLExpression ProcessReferenceAttribute(Path path, EntityMapping baseEntity, string[] references, string attributeName) { bool firstIsType = ((int)_ExprLevel.Peek() == EXPR); _ExprLevel.Push(_ExprLevel.Peek()); SelectStatement subQuery = new SelectStatement(baseEntity); int lastIndex = path.Identifiers.Count - 1; int referenceCounter = 0; if (!firstIsType) { for (int index = 0; index < lastIndex; index++) { string refName = path.Identifiers[index].Value; ReferenceMapping refeMap = baseEntity.References[refName]; // If refeMap == null, cannot find the reference in the child // Then try to get it from parent types if (refeMap == null) { Evaluant.Uss.Models.Entity current = Model.GetEntity(baseEntity.Type); if (refeMap == null) { while (Model.GetParent(current) != null) { current = Model.GetParent(current); refeMap = _Mapping.Entities[current.Type].References[refName]; if (refeMap != null) break; } } } if (refeMap == null) throw new SqlMapperException(string.Concat("Cannot find the reference", refName, " from the entity ", baseEntity.Type)); referenceCounter += 1; //entityMap = _Mapping.Entities.GetEntity(refeMap.EntityChild); } } TableSource currentTable = new TableSource(baseEntity, baseEntity.Table, CreateUniqueTableAlias()); tableContext.Push(currentTable); queryContext.Push(subQuery); bool overrideId = false; if (referenceCounter > 1) overrideId = true; ConvertToSQL(path, false, true, true, overrideId); entityMappingContext.Pop(); subQuery = (SelectStatement)queryContext.Peek(); //// the exists function just need ids fields //// do not list attribute field to avoid problems with data type fields (text, ntext, image for sql server) //// Remove none needed selected item, according to the path //// no references: keep Type, Id (2 fields) //// references: keep Type, IdParent, Id (3 fields) int keepFieldNb = (path.Identifiers.Count == 1) ? 2 : 3; if (subQuery is UnionStatement) { foreach (SelectStatement select in ((UnionStatement)subQuery).SelectExpressions) { for (int i = select.SelectList.Count - 1; i >= keepFieldNb; i--) select.SelectList.RemoveAt(i); // link tables for inline views select.WhereClause.SearchCondition.Add(new BinaryLogicExpression(linkTableContext.Pop() as Column, BinaryLogicOperator.Equals, linkTableContext.Pop() as Column)); } } else { for (int i = subQuery.SelectList.Count - 1; i >= keepFieldNb; i--) subQuery.SelectList.RemoveAt(i); // link tables for inline views subQuery.WhereClause.SearchCondition.Add(new BinaryLogicExpression(linkTableContext.Pop() as Column, BinaryLogicOperator.Equals, linkTableContext.Pop() as Column)); } UnionStatement us = subQuery as UnionStatement; if (us != null) { foreach (SelectStatement s in us.SelectExpressions) { s.SelectList.Clear(); s.SelectList.Add(new Column(null, s.TableAlias, attributeName)); } } else { subQuery.SelectList.Clear(); subQuery.SelectList.Add(new Column(null, attributeName, subQuery.TableAlias)); } //subQuery.SelectedAllColumns = true; //expression = new ExistsPredicate(subQuery); //sqlExpressionContext.Push(subQuery); tableContext.Pop(); queryContext.Pop(); _ExprLevel.Pop(); //return expression; return subQuery; }
/// <summary> /// Initializes a new instance of the <see cref="AttributeMapping"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="type">Type.</param> /// <param name="parentEntity">Parent entity.</param> public AttributeMapping(string name, Type type, EntityMapping parentEntity) { this._Name = name; this._Type = type; this._ParentEntity = parentEntity; }
public bool Contains(EntityMapping value) { return base.List.Contains((object)value); }
public void Insert(int index, EntityMapping value) { base.List.Insert(index, (object)value); }
private void ImportAttributes(IDataReader reader, string[] attributes, EntityMapping entityMapping, Entity entity, Hashtable columnAliasMapping) { if (attributes != null && _Model.GetInheritedAttributes(entity.Type).Count > 0) { ArrayList attrs = new ArrayList(attributes); StringCollection names = new StringCollection(); AttributeMappingCollection attributeMappings = new AttributeMappingCollection(); attributeMappings.TypeName = entityMapping.Type; // Retrieve attributes of the current entity type and all its sub classes attributes foreach (AttributeMapping a in entityMapping.Attributes) attributeMappings.Add(a); IList children = _Model.GetTree(entityMapping.Type); if (children != null && children.Count > 0) { foreach (Evaluant.Uss.Models.Entity e in children) { EntityMapping currentEM = _Mapping.Entities[e.Type]; if (currentEM == null) throw new SqlMapperException(string.Concat("Cannot find the entity ", e.Type, " in your mapping file")); foreach (Evaluant.Uss.Models.Attribute a in e.Attributes) { if (attributeMappings[a.Name] == null) if (currentEM.Attributes[a.Name] != null) attributeMappings.Add(currentEM.Attributes[a.Name]); } } } foreach (AttributeMapping am in attributeMappings) { string fullAttributeName = _Model.GetFullAttributeName(am.Name, am.ParentEntity.Type); // load only specified attributes ? if (((attrs.Count > 0) && !attrs.Contains(fullAttributeName))) continue; //Process generic Attributes string name = string.Empty; if (am.Discriminator != null && am.Discriminator != string.Empty) if (reader[am.Discriminator] != DBNull.Value) name = (string)reader[am.Discriminator]; if (columnAliasMapping != null && columnAliasMapping[fullAttributeName] == null) continue; object val = columnAliasMapping == null ? reader[fullAttributeName] : reader[columnAliasMapping[fullAttributeName].ToString()]; string type = (am.Discriminator != null) ? reader[am.Discriminator].ToString() : am.Name; if (((type != string.Empty) && !names.Contains(type)) && (type == am.Name)) { Type t = am.Type; Evaluant.Uss.Models.Entity current = _Model.GetEntity(entity.Type); if (t == null && name != null && name != string.Empty) t = _Model.GetAttribute(entity.Type, name).Type; string attributeName = am.Name; if (t == null && entity != null && _Model.GetAttribute(entity.Type, attributeName) != null) t = _Model.GetAttribute(entity.Type, attributeName).Type; if (current != null && t == null) { while (_Model.GetParent(current) != null) { current = _Model.GetParent(current); if (_Model.GetAttribute(current.Type, attributeName) != null) t = _Model.GetAttribute(current.Type, attributeName).Type; } } if (current != null && t == null) { foreach (Evaluant.Uss.Models.Entity child in _Model.GetTree(current.Type)) if (_Model.GetAttribute(child.Type, attributeName) != null) t = _Model.GetAttribute(child.Type, attributeName).Type; } if (((t == null) || (!t.IsValueType && (t != typeof(string)))) && (am.Name == "*")) { object obj2 = Utils.UnSerialize((string)val); t = obj2.GetType(); } SerializableType serializable = am.GetSerializableType(am.DbType, t); if (val != DBNull.Value) { object sValue = null; switch (serializable) { case SerializableType.BinarySerialization: sValue = Utils.UnSerialize((byte[])val); break; case SerializableType.StringSerialization: sValue = Utils.UnSerialize((string)val); t = val.GetType(); break; case SerializableType.Standard: #if !EUSS11 if ((t.IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))) { sValue = new System.ComponentModel.NullableConverter(t).ConvertTo(val, t.GetGenericArguments()[0]); } else #endif { if (am.DbType == DbType.String) val = ((string)val).Trim(); sValue = Convert.ChangeType(val, t, CultureInfo.InvariantCulture); } break; case SerializableType.String: if (val.GetType() == t) sValue = val; else sValue = Utils.StringToObject((string)val, t); break; case SerializableType.Int: val = Convert.ToInt32(val); if (t.IsEnum) sValue = Enum.ToObject(t, val); else sValue = Convert.ChangeType(val, t, CultureInfo.InvariantCulture); break; } if (t == null) t = typeof(object); if (entity.FindEntry(type) == null) entity.AddValue(type, sValue, t, State.UpToDate); } names.Add(type); entity.State = State.UpToDate; } } } }
public CacheEntityEntry(EntityMapping mapping) : base(mapping) { }
private ISQLExpression ProcessAttributesWithLoadAttribute(SelectStatement mainQuery, SelectStatement currentQuery, Table currentTable, EntityMapping entityMap, Table attributeTable, AttributeMapping attributeMapping, string atrbId) { if (_IsFirstAttribute) { _IsFirstAttribute = false; // if current table is a JoinedTable : // from clause = mainQuery INNER JOIN attributeTable if (currentTable is JoinedTable) { JoinedTable lastJoinTable = new JoinedTable(mainQuery, TypeJoinedTable.LeftOuter, attributeTable); lastJoinTable.TableAlias = mainQuery.TableAlias; BinaryLogicExpression onCondition = new BinaryLogicExpression( new Column(entityMap.Ids[0], mainQuery.TableAlias, entityMap.GetIdField(entityMap.Ids[0])), BinaryLogicOperator.Equals, new Column(attributeMapping, attributeTable.TableAlias, atrbId)); if (mainQuery.WhereClause.SearchCondition.Count != 0) { foreach (ILogicExpression expression in mainQuery.WhereClause.SearchCondition) { onCondition = new BinaryLogicExpression(onCondition, BinaryLogicOperator.And, expression); } } lastJoinTable.SearchConditions.Add(new BinaryLogicExpression( new Column(entityMap.Ids[0], mainQuery.TableAlias, entityMap.GetIdField(entityMap.Ids[0])), BinaryLogicOperator.Equals, new Column(entityMap.Ids[0], attributeTable.TableAlias, atrbId))); currentQuery.TableAlias = mainQuery.TableAlias; currentQuery.FromClause.Add(lastJoinTable); tableContext.Push(lastJoinTable); for (int i = 0; i < 2; i++) { Column column = mainQuery.SelectList[i] as Column; if (column != null && column.ColumnName == entityMap.Ids[0].Field && entityMap.Ids[0].Generator.Name == GeneratorMapping.GeneratorType.inherited) { column.Alias = null; currentQuery.SelectList.Add(new Column(column.TagMapping, lastJoinTable.TableAlias, column.ColumnName, entityMap.GetIdFieldAs(entityMap.Ids[0]))); } else { currentQuery.SelectList.Add(mainQuery.SelectList[i]); } } if (entityMap.Ids[0].Generator.Name == GeneratorMapping.GeneratorType.inherited) { for (int i = 2; i < mainQuery.SelectList.Count; i++) { Column column = mainQuery.SelectList[i] as Column; if (column != null) { currentQuery.SelectList.Add(new Column(column.TagMapping, lastJoinTable.TableAlias, column.GetSelectName())); } } } if (attributeMapping.Discriminator != null) { currentQuery.SelectList.Add(new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Discriminator)); } queryContext.Push(currentQuery); string alias = (attributeMapping.Field != attributeMapping.Name) ? attributeMapping.Name : String.Empty; return new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Field); } // else // from clause = currentTable INNER JOIN attributeTable else { JoinedTable joinTable = new JoinedTable(currentTable, TypeJoinedTable.LeftOuter, attributeTable); joinTable.SearchConditions.Add(new BinaryLogicExpression( new Column(entityMap.Ids[0], currentTable.TableAlias, entityMap.GetIdField(entityMap.Ids[0])), BinaryLogicOperator.Equals, new Column(attributeMapping, attributeTable.TableAlias, atrbId))); currentQuery.TableAlias = currentTable.TableAlias; currentQuery.FromClause.Add(joinTable); currentQuery.WhereClause.SearchCondition = mainQuery.WhereClause.SearchCondition; foreach (ISQLExpression exp in mainQuery.SelectList) { if (!currentQuery.SelectList.Contains(exp)) currentQuery.SelectList.Add(exp); } tableContext.Push(joinTable); } } else { Table rightTable = ((JoinedTable)currentTable).RigthTable; JoinedTable joinTable = new JoinedTable(rightTable, TypeJoinedTable.LeftOuter, attributeTable); joinTable.SearchConditions.Add(new BinaryLogicExpression( new Column(attributeMapping, rightTable.TableAlias, atrbId), BinaryLogicOperator.Equals, new Column(attributeMapping, attributeTable.TableAlias, atrbId))); ((JoinedTable)currentTable).RigthTable = joinTable; currentQuery.TableAlias = currentTable.TableAlias; currentQuery.FromClause.Add(currentTable); currentQuery.WhereClause.SearchCondition = mainQuery.WhereClause.SearchCondition; tableContext.Push(currentTable); } foreach (ISQLExpression exp in mainQuery.SelectList) { if (!currentQuery.SelectList.Contains(exp)) { currentQuery.SelectList.Add(exp); } } if (attributeMapping.Discriminator != null) { currentQuery.SelectList.Add(new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Discriminator)); } queryContext.Push(currentQuery); string alias1 = (attributeMapping.Field != attributeMapping.Name) ? attributeMapping.Name : String.Empty; return new Column(attributeMapping, attributeTable.TableAlias, attributeMapping.Field, alias1); }