private static bool RemapsInheritedProperties( DbDatabaseMapping databaseMapping, DbEntityTypeMapping entityTypeMapping) { var inheritedProperties = entityTypeMapping.EntityType.Properties .Except(entityTypeMapping.EntityType.DeclaredProperties) .Except(entityTypeMapping.EntityType.GetKeyProperties()); foreach (var property in inheritedProperties) { var fragment = GetFragmentForPropertyMapping(entityTypeMapping, property); if (fragment != null) { // find if this inherited property is mapped to another table by a base type var baseType = entityTypeMapping.EntityType.BaseType; while (baseType != null) { if (databaseMapping.GetEntityTypeMappings(baseType) .Select(baseTypeMapping => GetFragmentForPropertyMapping(baseTypeMapping, property)) .Any( baseFragment => baseFragment != null && baseFragment.Table != fragment.Table)) { return true; } baseType = baseType.BaseType; } } } return false; }
private void ConfigurePropertyMappings( DbDatabaseMapping databaseMapping, EdmEntityType entityType, DbProviderManifest providerManifest, bool allowOverride = false) { Contract.Requires(databaseMapping != null); Contract.Requires(entityType != null); Contract.Requires(providerManifest != null); var entityTypeMappings = databaseMapping.GetEntityTypeMappings(entityType); var propertyMappings = from etm in entityTypeMappings from etmf in etm.TypeMappingFragments from pm in etmf.PropertyMappings select Tuple.Create(pm, etmf.Table); Configure(propertyMappings, providerManifest, allowOverride); foreach ( var derivedEntityType in databaseMapping.Model.GetEntityTypes().Where(et => et.BaseType == entityType)) { ConfigurePropertyMappings(databaseMapping, derivedEntityType, providerManifest, true); } }
private static DbTableMetadata FindParentTable( DbDatabaseMapping databaseMapping, DbTableMetadata fromTable, DbEntityTypeMapping entityTypeMapping, DbTableMetadata toTable, bool isMappingInheritedProperties, int configurationIndex, int configurationCount, out bool isSplitting) { DbTableMetadata parentTable = null; isSplitting = false; // Check for entity splitting first, since splitting on a derived type in TPT/TPC will always have fromTable != toTable if (entityTypeMapping.UsesOtherTables(toTable) || configurationCount > 1) { if (configurationIndex != 0) { // Entity Splitting case parentTable = entityTypeMapping.GetPrimaryTable(); isSplitting = true; } } if (parentTable == null && fromTable != toTable && !isMappingInheritedProperties) { // TPT case var baseType = entityTypeMapping.EntityType.BaseType; while (baseType != null && parentTable == null) { // Traverse to first anscestor with a mapping var baseMapping = databaseMapping.GetEntityTypeMappings(baseType).FirstOrDefault(); if (baseMapping != null) { parentTable = baseMapping.GetPrimaryTable(); } baseType = baseType.BaseType; } } return parentTable; }
internal void Configure( EdmEntityType entityType, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) { Contract.Requires(entityType != null); Contract.Requires(databaseMapping != null); Contract.Requires(providerManifest != null); var entityTypeMapping = databaseMapping.GetEntityTypeMapping(entityType.GetClrType()); if (entityTypeMapping != null) { VerifyAllCSpacePropertiesAreMapped( databaseMapping.GetEntityTypeMappings(entityType), entityTypeMapping.EntityType.DeclaredProperties, new List<EdmProperty>()); } ConfigurePropertyMappings(databaseMapping, entityType, providerManifest); ConfigureAssociationMappings(databaseMapping, entityType); ConfigureDependentKeys(databaseMapping); }
private bool DiscoverIsSharingWithBase( DbDatabaseMapping databaseMapping, EdmEntityType entityType, DbTableMetadata toTable) { var isSharingTableWithBase = false; if (entityType.BaseType != null) { var baseType = entityType.BaseType; var anyBaseMappings = false; while (baseType != null && !isSharingTableWithBase) { var baseMappings = databaseMapping.GetEntityTypeMappings(baseType); if (baseMappings.Any()) { isSharingTableWithBase = baseMappings.SelectMany(m => m.TypeMappingFragments).Any(tmf => tmf.Table == toTable); anyBaseMappings = true; } baseType = baseType.BaseType; } if (!anyBaseMappings) { isSharingTableWithBase = TableName == null || string.IsNullOrWhiteSpace(TableName.Name); } } return isSharingTableWithBase; }