public static void RemoveDefaultDiscriminator( this DbEntityTypeMappingFragment entityTypeMappingFragment, DbEntitySetMapping entitySetMapping) { //Contract.Requires(entityTypeMappingFragment != null); var discriminatorColumn = entityTypeMappingFragment.RemoveDefaultDiscriminatorCondition(); if (discriminatorColumn != null) { var table = entityTypeMappingFragment.Table; table.Columns .Where(c => c.Name.Equals(discriminatorColumn.Name, StringComparison.Ordinal)) .ToList() .Each(column => table.Columns.Remove(column)); } if (entitySetMapping != null && entityTypeMappingFragment.IsConditionOnlyFragment() && !entityTypeMappingFragment.ColumnConditions.Any()) { var entityTypeMapping = entitySetMapping.EntityTypeMappings.Single( etm => etm.TypeMappingFragments.Contains(entityTypeMappingFragment)); entityTypeMapping.TypeMappingFragments.Remove(entityTypeMappingFragment); if (entityTypeMapping.TypeMappingFragments.Count == 0) { entitySetMapping.EntityTypeMappings.Remove(entityTypeMapping); } } }
private void WriteEntitySetMappingElement(DbEntitySetMapping set) { _xmlWriter.WriteStartElement(MslConstants.Element_EntitySetMapping); _xmlWriter.WriteAttributeString(MslConstants.Attribute_Name, set.EntitySet.Name); foreach (var entityTypeMapping in set.EntityTypeMappings) { WriteEntityTypeMappingElement(entityTypeMapping); } _xmlWriter.WriteEndElement(); }
private static bool HasBaseWithIsTypeOf(DbEntitySetMapping entitySetMapping, EdmEntityType entityType) { var baseType = entityType.BaseType; while (baseType != null) { if (entitySetMapping.EntityTypeMappings .Where(etm => etm.EntityType == baseType) .Any(etm => etm.IsHierarchyMapping)) { return true; } baseType = baseType.BaseType; } return false; }
internal static DbEntitySetMapping AddEntitySetMapping( this DbDatabaseMapping databaseMapping, EdmEntitySet entitySet) { Contract.Requires(databaseMapping != null); Contract.Requires(entitySet != null); var entitySetMapping = new DbEntitySetMapping { EntitySet = entitySet }; databaseMapping .EntityContainerMappings .Single() .EntitySetMappings .Add(entitySetMapping); return entitySetMapping; }
public void Generate( EdmEntityType entityType, IEnumerable<EdmProperty> properties, DbEntitySetMapping entitySetMapping, DbEntityTypeMappingFragment entityTypeMappingFragment, IList<EdmProperty> propertyPath, bool createNewColumn) { Contract.Requires(entityType != null); Contract.Requires(properties != null); Contract.Requires(entityTypeMappingFragment != null); Contract.Requires(propertyPath != null); var rootDeclaredProperties = entityType.GetRootType().DeclaredProperties; foreach (var property in properties) { if (property.PropertyType.IsComplexType && propertyPath.Any( p => p.PropertyType.IsComplexType && (p.PropertyType.ComplexType == property.PropertyType.ComplexType))) { throw Error.CircularComplexTypeHierarchy(); } propertyPath.Add(property); if (property.PropertyType.IsComplexType) { Generate( entityType, property.PropertyType.ComplexType.DeclaredProperties, entitySetMapping, entityTypeMappingFragment, propertyPath, createNewColumn); } else { var tableColumn = entitySetMapping.EntityTypeMappings .SelectMany(etm => etm.TypeMappingFragments) .SelectMany(etmf => etmf.PropertyMappings) .Where(pm => pm.PropertyPath.SequenceEqual(propertyPath)) .Select(pm => pm.Column) .FirstOrDefault(); if (tableColumn == null || createNewColumn) { tableColumn = entityTypeMappingFragment.Table.AddColumn( string.Join("_", propertyPath.Select(p => p.Name))); MapTableColumn( property, tableColumn, !rootDeclaredProperties.Contains(propertyPath.First()), entityType.KeyProperties().Contains(property)); } entityTypeMappingFragment.PropertyMappings.Add( new DbEdmPropertyMapping { Column = tableColumn, PropertyPath = propertyPath.ToList() }); } propertyPath.Remove(property); } }