本文整理汇总了C#中System.Data.Entity.Core.Metadata.Edm.EntityType.GetRootType方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.GetRootType方法的具体用法?C# EntityType.GetRootType怎么用?C# EntityType.GetRootType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Entity.Core.Metadata.Edm.EntityType
的用法示例。
在下文中一共展示了EntityType.GetRootType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRootType_should_return_base_type_when_has_base_type
public void GetRootType_should_return_base_type_when_has_base_type()
{
var entityType = new EntityType("E", "N", DataSpace.CSpace)
{
BaseType = new EntityType("E", "N", DataSpace.CSpace)
};
Assert.Same(entityType.BaseType, entityType.GetRootType());
}
示例2: Generate
public void Generate(EntityType entityType, DbDatabaseMapping databaseMapping)
{
DebugCheck.NotNull(entityType);
DebugCheck.NotNull(databaseMapping);
var entitySet = databaseMapping.Model.GetEntitySet(entityType);
var entitySetMapping
= databaseMapping.GetEntitySetMapping(entitySet)
?? databaseMapping.AddEntitySetMapping(entitySet);
var entityTypeMapping =
entitySetMapping.EntityTypeMappings.FirstOrDefault(
m => m.EntityTypes.Contains(entitySet.ElementType))
?? entitySetMapping.EntityTypeMappings.FirstOrDefault();
var table
= entityTypeMapping != null
? entityTypeMapping.MappingFragments.First().Table
: databaseMapping.Database.AddTable(entityType.GetRootType().Name);
entityTypeMapping = new EntityTypeMapping(null);
var entityTypeMappingFragment
= new MappingFragment(databaseMapping.Database.GetEntitySet(table), entityTypeMapping, false);
entityTypeMapping.AddType(entityType);
entityTypeMapping.AddFragment(entityTypeMappingFragment);
entityTypeMapping.SetClrType(entityType.GetClrType());
entitySetMapping.AddTypeMapping(entityTypeMapping);
new PropertyMappingGenerator(_providerManifest)
.Generate(
entityType,
entityType.Properties,
entitySetMapping,
entityTypeMappingFragment,
new List<EdmProperty>(),
false);
}
示例3: Generate
public void Generate(
EntityType entityType,
IEnumerable<EdmProperty> properties,
EntitySetMapping entitySetMapping,
MappingFragment entityTypeMappingFragment,
IList<EdmProperty> propertyPath,
bool createNewColumn)
{
DebugCheck.NotNull(entityType);
DebugCheck.NotNull(properties);
DebugCheck.NotNull(entityTypeMappingFragment);
DebugCheck.NotNull(propertyPath);
var rootDeclaredProperties = entityType.GetRootType().DeclaredProperties;
foreach (var property in properties)
{
if (property.IsComplexType
&& propertyPath.Any(
p => p.IsComplexType
&& (p.ComplexType == property.ComplexType)))
{
throw Error.CircularComplexTypeHierarchy();
}
propertyPath.Add(property);
if (property.IsComplexType)
{
Generate(
entityType,
property.ComplexType.Properties,
entitySetMapping,
entityTypeMappingFragment,
propertyPath,
createNewColumn);
}
else
{
var tableColumn
= entitySetMapping.EntityTypeMappings
.SelectMany(etm => etm.MappingFragments)
.SelectMany(etmf => etmf.ColumnMappings)
.Where(pm => pm.PropertyPath.SequenceEqual(propertyPath))
.Select(pm => pm.ColumnProperty)
.FirstOrDefault();
if (tableColumn == null || createNewColumn)
{
var columnName
= string.Join("_", propertyPath.Select(p => p.Name));
tableColumn
= MapTableColumn(
property,
columnName,
!rootDeclaredProperties.Contains(propertyPath.First()));
entityTypeMappingFragment.Table.AddColumn(tableColumn);
if (entityType.KeyProperties().Contains(property))
{
entityTypeMappingFragment.Table.AddKeyMember(tableColumn);
}
}
entityTypeMappingFragment.AddColumnMapping(
new ColumnMappingBuilder(tableColumn, propertyPath.ToList()));
}
propertyPath.Remove(property);
}
}
示例4: GetEntitySet
public static EntitySet GetEntitySet(this EdmModel model, EntityType entityType)
{
DebugCheck.NotNull(model);
DebugCheck.NotNull(entityType);
Debug.Assert(model.Containers.Count() == 1);
return model.GetEntitySets().SingleOrDefault(e => e.ElementType == entityType.GetRootType());
}
示例5: UpdateColumnNamesForTableSharing
private static bool UpdateColumnNamesForTableSharing(
DbDatabaseMapping databaseMapping, EntityType entityType, EntityType toTable,
StorageMappingFragment fragment)
{
// Validate: this table can be used only if:
// 1. The table is not used by any other type
// 2. The table is used only by types in the same type hierarchy (TPH)
// 3. There is a 1:1 relationship and the PK count and types match (Table Splitting)
var typesSharingTable = FindAllTypesUsingTable(databaseMapping, toTable);
var associationsToSharedTable = new Dictionary<EntityType, List<AssociationType>>();
foreach (var candidateType in typesSharingTable)
{
var oneToOneAssocations = FindAllOneToOneFKAssociationTypes(
databaseMapping.Model, entityType, candidateType);
var rootType = candidateType.GetRootType();
if (!associationsToSharedTable.ContainsKey(rootType))
{
associationsToSharedTable.Add(rootType, oneToOneAssocations.ToList());
}
else
{
associationsToSharedTable[rootType].AddRange(oneToOneAssocations);
}
}
foreach (var candidateTypePair in associationsToSharedTable)
{
// Check if these types are in a TPH hierarchy
if (candidateTypePair.Key != entityType.GetRootType()
&& candidateTypePair.Value.Count == 0)
{
var tableName = toTable.GetTableName();
throw Error.EntityMappingConfiguration_InvalidTableSharing(
entityType.Name, candidateTypePair.Key.Name,
tableName != null ? tableName.Name : databaseMapping.Database.GetEntitySet(toTable).Table);
}
}
var allAssociations = associationsToSharedTable.Values.SelectMany(l => l);
if (allAssociations.Any())
{
var principalKeyNamesType = toTable.GetKeyNamesType();
if (principalKeyNamesType == null)
{
// grab a candidate
var association = allAssociations.First();
principalKeyNamesType = association.Constraint.FromRole.GetEntityType();
if (allAssociations.All(x => x.Constraint.FromRole.GetEntityType() == principalKeyNamesType))
{
toTable.SetKeyNamesType(principalKeyNamesType);
}
}
// rename the columns in the fragment to match the principal keys
var principalKeys = principalKeyNamesType.KeyProperties().ToArray();
var i = 0;
foreach (var k in entityType.KeyProperties())
{
var dependentColumn = fragment.ColumnMappings.Single(pm => pm.PropertyPath.First() == k).ColumnProperty;
dependentColumn.Name = principalKeys[i].Name;
i++;
}
return true;
}
return false;
}
示例6: ConfigureKey
private void ConfigureKey(EntityType entityType)
{
DebugCheck.NotNull(entityType);
if (!_keyProperties.Any())
{
return;
}
if (entityType.BaseType != null)
{
throw Error.KeyRegisteredOnDerivedType(ClrType, entityType.GetRootType().GetClrType());
}
var keyProperties = _keyProperties.AsEnumerable();
if (!_isKeyConfigured)
{
var primaryKeys
= from p in _keyProperties
select new
{
PropertyInfo = p,
Property(new PropertyPath(p)).ColumnOrder
};
if ((_keyProperties.Count > 1)
&& primaryKeys.Any(p => !p.ColumnOrder.HasValue))
{
throw Error.ModelGeneration_UnableToDetermineKeyOrder(ClrType);
}
keyProperties = primaryKeys.OrderBy(p => p.ColumnOrder).Select(p => p.PropertyInfo);
}
foreach (var keyProperty in keyProperties)
{
var property = entityType.GetDeclaredPrimitiveProperty(keyProperty);
if (property == null)
{
throw Error.KeyPropertyNotFound(keyProperty.Name, entityType.Name);
}
property.Nullable = false;
entityType.AddKeyMember(property);
}
}