本文整理汇总了C#中System.Data.Entity.Core.Metadata.Edm.DbDatabaseMapping类的典型用法代码示例。如果您正苦于以下问题:C# DbDatabaseMapping类的具体用法?C# DbDatabaseMapping怎么用?C# DbDatabaseMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbDatabaseMapping类属于System.Data.Entity.Core.Metadata.Edm命名空间,在下文中一共展示了DbDatabaseMapping类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:28,代码来源:EntityMappingConfigurationTests.cs
示例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);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:33,代码来源:AssociationTypeMappingGenerator.cs
示例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();
}
开发者ID:hallco978,项目名称:entityframework,代码行数:25,代码来源:EdmxSerializer.cs
示例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;
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:32,代码来源:ColumnMappingBuilderExtensions.cs
示例6: WriteSchema
internal void WriteSchema(DbDatabaseMapping databaseMapping)
{
DebugCheck.NotNull(databaseMapping);
WriteSchemaElementHeader();
WriteDbModelElement(databaseMapping);
WriteEndElement();
}
开发者ID:hallco978,项目名称:entityframework,代码行数:8,代码来源:MslXmlSchemaWriter.cs
示例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;
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:DbModel.cs
示例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());
}
开发者ID:hallco978,项目名称:entityframework,代码行数:9,代码来源:MslXmlSchemaWriter.cs
示例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;
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:10,代码来源:DatabaseMappingGenerator.cs
示例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);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:DbDatabaseMappingTests.cs
示例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);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:DbDatabaseMappingTests.cs
示例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());
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:DbDatabaseMappingTests.cs
示例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;
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:16,代码来源:MslSerializer.cs
示例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);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:12,代码来源:ManyToManyCascadeDeleteConvention.cs
示例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;
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:16,代码来源:CodeFirstCachedMetadataWorkspace.cs
示例16: SerializeToString
internal static string SerializeToString(DbDatabaseMapping databaseMapping)
{
var edmx = new StringBuilder();
new EdmxSerializer().Serialize(
databaseMapping,
XmlWriter.Create(
edmx, new XmlWriterSettings
{
Indent = true
}));
return edmx.ToString();
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:12,代码来源:DbDatabaseMappingExtensions.cs
示例17: GenerateEntityTypes
private void GenerateEntityTypes(DbDatabaseMapping databaseMapping)
{
DebugCheck.NotNull(databaseMapping);
foreach (var entityType in databaseMapping.Model.EntityTypes)
{
if (!entityType.Abstract)
{
new TableMappingGenerator(_providerManifest).
Generate(entityType, databaseMapping);
}
}
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:13,代码来源:DatabaseMappingGenerator.cs
示例18: UpdateEdmxFromModel_updates_csdl_ssdl_msl
public void UpdateEdmxFromModel_updates_csdl_ssdl_msl()
{
var inputXml = XDocument.Parse("<root />");
var databaseMapping =
new DbDatabaseMapping
{
Model = new EdmModel(DataSpace.CSpace),
Database = new EdmModel(DataSpace.SSpace)
};
var model = new DbModel(databaseMapping, new DbModelBuilder());
var mockEdmxHelper = new Mock<EdmxHelper>(inputXml);
mockEdmxHelper.Setup(
h => h.UpdateStorageModels(
It.Is<EdmModel>(m => m == databaseMapping.Database),
It.Is<string>(n => n == "storeNamespace"),
It.Is<DbProviderInfo>(i => i == model.ProviderInfo),
It.IsAny<List<EdmSchemaError>>()))
.Returns(true);
mockEdmxHelper.Setup(
h => h.UpdateConceptualModels(
It.Is<EdmModel>(m => m == databaseMapping.Model),
It.Is<string>(n => n == "entityModelNamespace")))
.Returns(true);
mockEdmxHelper.Setup(
h => h.UpdateMapping(
It.Is<DbModel>(m => m == model)))
.Returns(true);
mockEdmxHelper.Object.UpdateEdmxFromModel(
model, "storeNamespace", "entityModelNamespace", new List<EdmSchemaError>());
mockEdmxHelper
.Verify(
h => h.UpdateStorageModels(
It.Is<EdmModel>(m => m == databaseMapping.Database),
It.Is<string>(n => n == "storeNamespace"),
It.Is<DbProviderInfo>(i => i == model.ProviderInfo),
It.IsAny<List<EdmSchemaError>>()), Times.Once());
mockEdmxHelper
.Verify(
h => h.UpdateConceptualModels(
It.Is<EdmModel>(m => m == databaseMapping.Model),
It.Is<string>(n => n == "entityModelNamespace")), Times.Once());
mockEdmxHelper
.Verify(
h => h.UpdateMapping(
It.Is<DbModel>(m => m == model)), Times.Once());
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:50,代码来源:EdmxHelperTests.cs
示例19: Build
public static DbModel Build(SimpleMappingContext mappingContext)
{
Debug.Assert(mappingContext != null, "mappingContext != null");
var databaseMapping =
new DbDatabaseMapping
{
Database = mappingContext.StoreModel,
Model = BuildEntityModel(mappingContext)
};
databaseMapping.AddEntityContainerMapping(BuildEntityContainerMapping(mappingContext));
return new DbModel(databaseMapping, new DbModelBuilder());
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:15,代码来源:DbDatabaseMappingBuilder.cs
示例20: GenerateEntityTypes
private static void GenerateEntityTypes(DbDatabaseMapping databaseMapping)
{
DebugCheck.NotNull(databaseMapping);
foreach (var entityType in databaseMapping.Model.EntityTypes)
{
if (entityType.Abstract
&& databaseMapping.Model.EntityTypes.All(e => e.BaseType != entityType))
{
throw new InvalidOperationException(Strings.UnmappedAbstractType(entityType.GetClrType()));
}
new TableMappingGenerator(databaseMapping.ProviderManifest).
Generate(entityType, databaseMapping);
}
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:16,代码来源:DatabaseMappingGenerator.cs
注:本文中的System.Data.Entity.Core.Metadata.Edm.DbDatabaseMapping类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论