本文整理汇总了C#中System.Data.Entity.Core.Metadata.Edm.DbDatabaseMapping.GetEntityTypeMapping方法的典型用法代码示例。如果您正苦于以下问题:C# DbDatabaseMapping.GetEntityTypeMapping方法的具体用法?C# DbDatabaseMapping.GetEntityTypeMapping怎么用?C# DbDatabaseMapping.GetEntityTypeMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Entity.Core.Metadata.Edm.DbDatabaseMapping
的用法示例。
在下文中一共展示了DbDatabaseMapping.GetEntityTypeMapping方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEntityTypeMappingInHierarchy
protected static StorageEntityTypeMapping GetEntityTypeMappingInHierarchy(
DbDatabaseMapping databaseMapping, EntityType entityType)
{
DebugCheck.NotNull(databaseMapping);
DebugCheck.NotNull(entityType);
var entityTypeMapping = databaseMapping.GetEntityTypeMapping(entityType);
if (entityTypeMapping == null)
{
var entitySetMapping =
databaseMapping.GetEntitySetMapping(databaseMapping.Model.GetEntitySet(entityType));
if (entitySetMapping != null)
{
entityTypeMapping = entitySetMapping
.EntityTypeMappings
.First(
etm => entityType.DeclaredProperties.All(
dp => etm.MappingFragments.First()
.ColumnMappings.Select(pm => pm.PropertyPath.First()).Contains(dp)));
}
}
if (entityTypeMapping == null)
{
throw Error.UnmappedAbstractType(entityType.GetClrType());
}
return entityTypeMapping;
}
示例2: UpdatePrincipalTables
private static void UpdatePrincipalTables(
DbDatabaseMapping databaseMapping, EntityType toTable, bool removeFks,
AssociationType associationType, EntityType et)
{
AssociationEndMember principalEnd, dependentEnd;
var endsToCheck = new List<AssociationEndMember>();
if (associationType.TryGuessPrincipalAndDependentEnds(out principalEnd, out dependentEnd))
{
endsToCheck.Add(principalEnd);
}
else if (associationType.SourceEnd.RelationshipMultiplicity == RelationshipMultiplicity.Many
&& associationType.TargetEnd.RelationshipMultiplicity == RelationshipMultiplicity.Many)
{
// many to many consider both ends
endsToCheck.Add(associationType.SourceEnd);
endsToCheck.Add(associationType.TargetEnd);
}
else
{
// 1:1 and 0..1:0..1
endsToCheck.Add(associationType.SourceEnd);
}
foreach (var end in endsToCheck)
{
if (end.GetEntityType() == et)
{
IEnumerable<KeyValuePair<EntityType, IEnumerable<EdmProperty>>> dependentTableInfos;
if (associationType.Constraint != null)
{
var originalDependentType = associationType.GetOtherEnd(end).GetEntityType();
var allDependentTypes = databaseMapping.Model.GetSelfAndAllDerivedTypes(originalDependentType);
dependentTableInfos =
allDependentTypes.Select(t => databaseMapping.GetEntityTypeMapping(t)).Where(
dm => dm != null)
.SelectMany(
dm => dm.MappingFragments
.Where(
tmf => associationType.Constraint.ToProperties
.All(
p =>
tmf.ColumnMappings.Any(
pm => pm.PropertyPath.First() == p))))
.Distinct((f1, f2) => f1.Table == f2.Table)
.Select(
df =>
new KeyValuePair<EntityType, IEnumerable<EdmProperty>>(
df.Table,
df.ColumnMappings.Where(
pm =>
associationType.Constraint.ToProperties.Contains(
pm.PropertyPath.First())).Select(
pm => pm.ColumnProperty)));
}
else
{
// IA
var associationSetMapping =
databaseMapping.EntityContainerMappings
.Single().AssociationSetMappings
.Single(asm => asm.AssociationSet.ElementType == associationType);
var dependentTable = associationSetMapping.Table;
var propertyMappings = associationSetMapping.SourceEndMapping.AssociationEnd == end
? associationSetMapping.SourceEndMapping.PropertyMappings
: associationSetMapping.TargetEndMapping.PropertyMappings;
var dependentColumns = propertyMappings.Select(pm => pm.Column);
dependentTableInfos = new[]
{
new KeyValuePair
<EntityType, IEnumerable<EdmProperty>>(
dependentTable, dependentColumns)
};
}
foreach (var tableInfo in dependentTableInfos)
{
foreach (
var fk in
tableInfo.Key.ForeignKeyBuilders.Where(
fk => fk.DependentColumns.SequenceEqual(tableInfo.Value)).ToArray(
))
{
if (removeFks)
{
tableInfo.Key.RemoveForeignKey(fk);
}
else if (fk.GetAssociationType() == null || fk.GetAssociationType() == associationType)
{
fk.PrincipalTable = toTable;
}
}
}
}
}
}
示例3: FindOrCreateTypeMappingFragment
private StorageMappingFragment FindOrCreateTypeMappingFragment(
DbDatabaseMapping databaseMapping,
ref StorageEntityTypeMapping entityTypeMapping,
int configurationIndex,
EntityType entityType,
DbProviderManifest providerManifest)
{
StorageMappingFragment fragment = null;
if (entityTypeMapping == null)
{
Debug.Assert(entityType.Abstract);
new TableMappingGenerator(providerManifest).
Generate(entityType, databaseMapping);
entityTypeMapping = databaseMapping.GetEntityTypeMapping(entityType);
configurationIndex = 0;
}
if (configurationIndex < entityTypeMapping.MappingFragments.Count)
{
fragment = entityTypeMapping.MappingFragments[configurationIndex];
}
else
{
if (MapInheritedProperties)
{
throw Error.EntityMappingConfiguration_DuplicateMapInheritedProperties(entityType.Name);
}
else if (Properties == null)
{
throw Error.EntityMappingConfiguration_DuplicateMappedProperties(entityType.Name);
}
else
{
Properties.Each(
p =>
{
if (
PropertyPathToEdmPropertyPath(p, entityType).Any(
pp => !entityType.KeyProperties().Contains(pp.First())))
{
throw Error.EntityMappingConfiguration_DuplicateMappedProperty(
entityType.Name, p.ToString());
}
});
}
// Special case where they've asked for an extra table related to this type that only will include the PK columns
// Uniquify: can be false, always move to a new table
var templateTable = entityTypeMapping.MappingFragments[0].Table;
var table = databaseMapping.Database.AddTable(templateTable.Name, templateTable);
fragment
= EntityMappingOperations.CreateTypeMappingFragment(
entityTypeMapping,
entityTypeMapping.MappingFragments[0],
databaseMapping.Database.GetEntitySet(table));
}
return fragment;
}
示例4: DiscoverAllMappingsToContain
private HashSet<EdmPropertyPath> DiscoverAllMappingsToContain(
DbDatabaseMapping databaseMapping, EntityType entityType, EntityType toTable,
bool isSharingTableWithBase)
{
// Ensure all specified properties are the only ones present in this fragment and table
var mappingsToContain = new HashSet<EdmPropertyPath>();
// Include Key Properties always
entityType.KeyProperties().Each(
p =>
mappingsToContain.AddRange(p.ToPropertyPathList()));
// Include All Inherited Properties
if (MapInheritedProperties)
{
entityType.Properties.Except(entityType.DeclaredProperties).Each(
p =>
mappingsToContain.AddRange(p.ToPropertyPathList()));
}
// If sharing table with base type, include all the mappings that the base has
if (isSharingTableWithBase)
{
var baseMappingsToContain = new HashSet<EdmPropertyPath>();
var baseType = (EntityType)entityType.BaseType;
StorageEntityTypeMapping baseMapping = null;
StorageMappingFragment baseFragment = null;
// if the base is abstract it may have no mapping so look upwards until you find either:
// 1. a type with mappings and
// 2. if none can be found (abstract until the root or hit another table), then include all declared properties on that base type
while (baseType != null
&& baseMapping == null)
{
baseMapping = databaseMapping.GetEntityTypeMapping((EntityType)entityType.BaseType);
if (baseMapping != null)
{
baseFragment = baseMapping.MappingFragments.SingleOrDefault(tmf => tmf.Table == toTable);
}
if (baseFragment == null)
{
baseType.DeclaredProperties.Each(
p =>
baseMappingsToContain.AddRange(p.ToPropertyPathList()));
}
baseType = (EntityType)baseType.BaseType;
}
if (baseFragment != null)
{
foreach (var pm in baseFragment.ColumnMappings)
{
mappingsToContain.Add(new EdmPropertyPath(pm.PropertyPath));
}
}
mappingsToContain.AddRange(baseMappingsToContain);
}
if (Properties == null)
{
// Include All Declared Properties
entityType.DeclaredProperties.Each(
p =>
mappingsToContain.AddRange(p.ToPropertyPathList()));
}
else
{
// Include Specific Properties
Properties.Each(
p =>
mappingsToContain.AddRange(PropertyPathToEdmPropertyPath(p, entityType)));
}
return mappingsToContain;
}
示例5: ConfigureEntityTypes
private void ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
{
var sortedEntityConfigurations =
SortEntityConfigurationsByInheritance(databaseMapping);
foreach (var entityTypeConfiguration in sortedEntityConfigurations)
{
var entityTypeMapping
= databaseMapping.GetEntityTypeMapping(entityTypeConfiguration.ClrType);
entityTypeConfiguration.ConfigureTablesAndConditions(
entityTypeMapping, databaseMapping, providerManifest);
// run through all unconfigured derived types of the current entityType to make sure the property mappings now point to the right places
ConfigureUnconfiguredDerivedTypes(
databaseMapping,
providerManifest,
databaseMapping.Model.GetEntityType(entityTypeConfiguration.ClrType),
sortedEntityConfigurations);
}
new EntityMappingService(databaseMapping).Configure();
foreach (var entityType in databaseMapping.Model.GetEntityTypes().Where(e => e.GetConfiguration() != null))
{
var entityTypeConfiguration = (EntityTypeConfiguration)entityType.GetConfiguration();
entityTypeConfiguration.Configure(entityType, databaseMapping, providerManifest);
}
}
示例6: FindBaseTableForExtraPropertyMapping
private static EntityType FindBaseTableForExtraPropertyMapping(
DbDatabaseMapping databaseMapping, EntityType entityType, ColumnMappingBuilder pm)
{
var baseType = (EntityType)entityType.BaseType;
StorageMappingFragment baseFragment = null;
while (baseType != null
&& baseFragment == null)
{
var baseMapping = databaseMapping.GetEntityTypeMapping(baseType);
if (baseMapping != null)
{
baseFragment =
baseMapping.MappingFragments.SingleOrDefault(
f => f.ColumnMappings.Any(bpm => bpm.PropertyPath.SequenceEqual(pm.PropertyPath)));
if (baseFragment != null)
{
return baseFragment.Table;
}
}
baseType = (EntityType)baseType.BaseType;
}
return null;
}
示例7: Configure
internal void Configure(
EntityType entityType,
DbDatabaseMapping databaseMapping,
DbProviderManifest providerManifest)
{
DebugCheck.NotNull(entityType);
DebugCheck.NotNull(databaseMapping);
DebugCheck.NotNull(providerManifest);
var entityTypeMapping
= databaseMapping.GetEntityTypeMapping(entityType.GetClrType());
if (entityTypeMapping != null)
{
VerifyAllCSpacePropertiesAreMapped(
databaseMapping.GetEntityTypeMappings(entityType).ToList(),
entityTypeMapping.EntityType.DeclaredProperties,
new List<EdmProperty>());
}
ConfigurePropertyMappings(databaseMapping, entityType, providerManifest);
ConfigureAssociationMappings(databaseMapping, entityType, providerManifest);
ConfigureDependentKeys(databaseMapping, providerManifest);
ConfigureModificationFunctions(databaseMapping, entityType, providerManifest);
}
示例8: ConfigureUnconfiguredType
internal static void ConfigureUnconfiguredType(
DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest, EntityType entityType)
{
var c = new EntityMappingConfiguration();
var entityTypeMapping
= databaseMapping.GetEntityTypeMapping(entityType.GetClrType());
c.Configure(databaseMapping, providerManifest, entityType, ref entityTypeMapping, false, 0, 1);
}
示例9: ConfigureUnconfiguredType
internal static void ConfigureUnconfiguredType(
DbDatabaseMapping databaseMapping,
ICollection<EntitySet> entitySets,
DbProviderManifest providerManifest,
EntityType entityType,
IDictionary<string, object> commonAnnotations)
{
var c = new EntityMappingConfiguration();
var entityTypeMapping
= databaseMapping.GetEntityTypeMapping(entityType.GetClrType());
c.Configure(databaseMapping, entitySets, providerManifest, entityType, ref entityTypeMapping, false, 0, 1, commonAnnotations);
}