本文整理汇总了C#中System.Data.Entity.Core.Metadata.Edm.DbDatabaseMapping类的典型用法代码示例。如果您正苦于以下问题:C# DbDatabaseMapping类的具体用法?C# DbDatabaseMapping怎么用?C# DbDatabaseMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbDatabaseMapping类属于System.Data.Entity.Core.Metadata.Edm命名空间,在下文中一共展示了DbDatabaseMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure_should_update_table_name_when_base_type_is_null
public void Configure_should_update_table_name_when_base_type_is_null()
{
var entityMappingConfiguration
= new EntityMappingConfiguration
{
TableName = new DatabaseName("Foo")
};
var entityTypeMapping = new EntityTypeMapping(null);
entityTypeMapping.AddType(new EntityType("E", "N", DataSpace.CSpace));
var databaseMapping =
new DbDatabaseMapping().Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace));
var table = databaseMapping.Database.AddTable("foo");
var entitySet = databaseMapping.Database.GetEntitySet(table);
entityTypeMapping.AddFragment(new MappingFragment(entitySet, entityTypeMapping, false));
entityMappingConfiguration.Configure(
databaseMapping, databaseMapping.Model.Container.EntitySets,
ProviderRegistry.Sql2008_ProviderManifest, entityTypeMapping.EntityType,
ref entityTypeMapping, false, 0, 1,
new Dictionary<string, object>());
Assert.Equal("Foo", table.GetTableName().Name);
}
示例2: GenerateForeignKeyAssociationType
private static void GenerateForeignKeyAssociationType(
AssociationType associationType, DbDatabaseMapping databaseMapping)
{
DebugCheck.NotNull(associationType);
DebugCheck.NotNull(databaseMapping);
Debug.Assert(associationType.Constraint != null);
var dependentEnd = associationType.Constraint.DependentEnd;
var principalEnd = associationType.GetOtherEnd(dependentEnd);
var principalEntityTypeMapping = GetEntityTypeMappingInHierarchy(databaseMapping, principalEnd.GetEntityType());
var dependentEntityTypeMapping = GetEntityTypeMappingInHierarchy(databaseMapping, dependentEnd.GetEntityType());
var foreignKeyConstraint
= new ForeignKeyBuilder(databaseMapping.Database, associationType.Name)
{
PrincipalTable =
principalEntityTypeMapping.MappingFragments.Single().Table,
DeleteAction = principalEnd.DeleteBehavior != OperationAction.None
? principalEnd.DeleteBehavior
: OperationAction.None
};
dependentEntityTypeMapping
.MappingFragments
.Single()
.Table
.AddForeignKey(foreignKeyConstraint);
foreignKeyConstraint.DependentColumns = associationType.Constraint.ToProperties.Select(
dependentProperty => dependentEntityTypeMapping.GetPropertyMapping(dependentProperty).ColumnProperty);
foreignKeyConstraint.SetAssociationType(associationType);
}
示例3: Serialize
public void Serialize(DbDatabaseMapping databaseMapping, XmlWriter xmlWriter)
{
DebugCheck.NotNull(xmlWriter);
DebugCheck.NotNull(databaseMapping);
Debug.Assert(databaseMapping.Model != null);
Debug.Assert(databaseMapping.Database != null);
_xmlWriter = xmlWriter;
_databaseMapping = databaseMapping;
_version = databaseMapping.Model.SchemaVersion;
_namespace = Equals(_version, XmlConstants.EdmVersionForV3)
? EdmXmlNamespaceV3
: (Equals(_version, XmlConstants.EdmVersionForV2) ? EdmXmlNamespaceV2 : EdmXmlNamespaceV1);
_xmlWriter.WriteStartDocument();
using (Element("Edmx", "Version", string.Format(CultureInfo.InvariantCulture, "{0:F1}", _version)))
{
WriteEdmxRuntime();
WriteEdmxDesigner();
}
_xmlWriter.WriteEndDocument();
_xmlWriter.Flush();
}
示例4: RemapsInheritedProperties
private static bool RemapsInheritedProperties(
DbDatabaseMapping databaseMapping, StorageEntityTypeMapping 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 = (EntityType)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 = (EntityType)baseType.BaseType;
}
}
}
return false;
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:31,代码来源:MappingInheritedPropertiesSupportConvention.cs
示例5: SyncNullabilityCSSpace
public static void SyncNullabilityCSSpace(
this ColumnMappingBuilder propertyMappingBuilder,
DbDatabaseMapping databaseMapping,
IEnumerable<EntitySet> entitySets,
EntityType toTable)
{
DebugCheck.NotNull(propertyMappingBuilder);
var property = propertyMappingBuilder.PropertyPath.Last();
EntitySetMapping setMapping = null;
var baseType = (EntityType)property.DeclaringType.BaseType;
if (baseType != null)
{
setMapping = GetEntitySetMapping(databaseMapping, baseType, entitySets);
}
while (baseType != null)
{
if (toTable == setMapping.EntityTypeMappings.First(m => m.EntityType == baseType).GetPrimaryTable())
{
// CodePlex 2254: If current table is part of TPH mapping below the TPT mapping we are processing, then
// don't change the nullability because the TPH nullability calculated previously is still correct.
return;
}
baseType = (EntityType)baseType.BaseType;
}
propertyMappingBuilder.ColumnProperty.Nullable = property.Nullable;
}
示例6: WriteSchema
internal void WriteSchema(DbDatabaseMapping databaseMapping)
{
DebugCheck.NotNull(databaseMapping);
WriteSchemaElementHeader();
WriteDbModelElement(databaseMapping);
WriteEndElement();
}
示例7: DbModel
// <summary>
// Initializes a new instance of the <see cref="DbModel" /> class.
// </summary>
internal DbModel(DbDatabaseMapping databaseMapping, DbModelBuilder modelBuilder)
{
DebugCheck.NotNull(databaseMapping);
DebugCheck.NotNull(modelBuilder);
_databaseMapping = databaseMapping;
_cachedModelBuilder = modelBuilder;
}
示例8: WriteDbModelElement
private void WriteDbModelElement(DbDatabaseMapping databaseMapping)
{
DebugCheck.NotNull(databaseMapping);
_entityTypeNamespace = databaseMapping.Model.NamespaceNames.SingleOrDefault();
_dbSchemaName = databaseMapping.Database.Containers.Single().Name;
WriteEntityContainerMappingElement(databaseMapping.EntityContainerMappings.First());
}
示例9: InitializeDatabaseMapping
private static DbDatabaseMapping InitializeDatabaseMapping(EdmModel model)
{
DebugCheck.NotNull(model);
var databaseMapping
= new DbDatabaseMapping()
.Initialize(model, new EdmModel(DataSpace.SSpace, model.SchemaVersion));
return databaseMapping;
}
示例10: Can_set_and_get_Model
public void Can_set_and_get_Model()
{
var mapping = new DbDatabaseMapping();
Assert.Null(mapping.Model);
var model = new EdmModel(DataSpace.CSpace);
mapping.Model = model;
Assert.Same(model, mapping.Model);
}
示例11: Can_set_and_get_Database
public void Can_set_and_get_Database()
{
var mapping = new DbDatabaseMapping();
Assert.Null(mapping.Database);
var storeModel = new EdmModel(DataSpace.SSpace);
mapping.Database = storeModel;
Assert.Same(storeModel, mapping.Database);
}
示例12: Can_add_container_mappings
public void Can_add_container_mappings()
{
var mapping = new DbDatabaseMapping();
Assert.Empty(mapping.EntityContainerMappings);
var containerMapping = new EntityContainerMapping(new EntityContainer());
mapping.AddEntityContainerMapping(containerMapping);
Assert.Same(containerMapping, mapping.EntityContainerMappings.Single());
}
示例13: Serialize
/// <summary>
/// Serialize the <see cref="DbModel" /> to the XmlWriter
/// </summary>
/// <param name="databaseMapping"> The DbModel to serialize </param>
/// <param name="xmlWriter"> The XmlWriter to serialize to </param>
public virtual bool Serialize(DbDatabaseMapping databaseMapping, XmlWriter xmlWriter)
{
Check.NotNull(databaseMapping, "databaseMapping");
Check.NotNull(xmlWriter, "xmlWriter");
var schemaWriter = new MslXmlSchemaWriter(xmlWriter, databaseMapping.Model.SchemaVersion);
schemaWriter.WriteSchema(databaseMapping);
return true;
}
示例14:
void IDbMappingConvention.Apply(DbDatabaseMapping databaseMapping)
{
Check.NotNull(databaseMapping, "databaseMapping");
databaseMapping.EntityContainerMappings
.SelectMany(ecm => ecm.AssociationSetMappings)
.Where(
asm => asm.AssociationSet.ElementType.IsManyToMany()
&& !asm.AssociationSet.ElementType.IsSelfReferencing())
.SelectMany(asm => asm.Table.ForeignKeyBuilders)
.Each(fk => fk.DeleteAction = OperationAction.Cascade);
}
示例15: CodeFirstCachedMetadataWorkspace
// <summary>
// Builds and stores the workspace based on the given code first configuration.
// </summary>
// <param name="databaseMapping"> The code first EDM model. </param>
public CodeFirstCachedMetadataWorkspace(DbDatabaseMapping databaseMapping)
{
DebugCheck.NotNull(databaseMapping);
_providerInfo = databaseMapping.ProviderInfo;
_metadataWorkspace = databaseMapping.ToMetadataWorkspace();
_assemblies = databaseMapping.Model.GetClrTypes().Select(t => t.Assembly()).Distinct().ToList();
Debug.Assert(databaseMapping.Model.Containers.Count() == 1, "Expecting Code First to create only one container.");
_defaultContainerName = databaseMapping.Model.Containers.First().Name;
}