本文整理汇总了C#中Microsoft.Data.Entity.Metadata.Model类的典型用法代码示例。如果您正苦于以下问题:C# Model类的具体用法?C# Model怎么用?C# Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Model类属于Microsoft.Data.Entity.Metadata命名空间,在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Replaces_existing_navigation_to_principal
public virtual void Replaces_existing_navigation_to_principal()
{
var model = new Model();
var modelBuilder = CreateModelBuilder(model);
modelBuilder.Entity<CustomerDetails>().Reference(c => c.Customer).InverseReference();
modelBuilder.Ignore<Order>();
var dependentType = model.GetEntityType(typeof(CustomerDetails));
var principalType = model.GetEntityType(typeof(Customer));
var expectedPrincipalProperties = principalType.Properties.ToList();
var expectedDependentProperties = dependentType.Properties.ToList();
var principalKey = principalType.GetKeys().Single();
var dependentKey = dependentType.GetKeys().Single();
modelBuilder.Entity<Customer>().Reference(e => e.Details).InverseReference(e => e.Customer);
var fk = dependentType.GetForeignKeys().Single();
Assert.Same(fk.DependentToPrincipal, dependentType.Navigations.Single());
Assert.Same(fk.PrincipalToDependent, principalType.Navigations.Single());
AssertEqual(expectedPrincipalProperties, principalType.Properties);
AssertEqual(expectedDependentProperties, dependentType.Properties);
Assert.Empty(principalType.GetForeignKeys());
Assert.Same(principalKey, principalType.GetKeys().Single());
Assert.Same(dependentKey, dependentType.GetKeys().Single());
Assert.Same(principalKey, principalType.GetPrimaryKey());
Assert.Same(dependentKey, dependentType.GetPrimaryKey());
}
示例2: CreateModel
protected Model CreateModel()
{
var model = new Model();
var modelBuilder = new BasicModelBuilder(model);
modelBuilder.Entity<MappingQueryTestBase.MappedCustomer>(e =>
{
e.Key(c => c.CustomerID);
e.Property(c => c.CompanyName2).Metadata.Relational().Column = "Broken";
e.Metadata.Relational().Table = "Broken";
e.Metadata.Relational().Schema = "wrong";
});
modelBuilder.Entity<MappingQueryTestBase.MappedEmployee>(e =>
{
e.Key(em => em.EmployeeID);
e.Property(em => em.City2).Metadata.Relational().Column = "City";
e.Metadata.Relational().Table = "Employees";
e.Metadata.Relational().Schema = "dbo";
});
modelBuilder.Entity<MappingQueryTestBase.MappedOrder>(e =>
{
e.Key(o => o.OrderID);
e.Property(em => em.ShipVia2).Metadata.Relational().Column = "ShipVia";
e.Metadata.Relational().Table = "Orders";
e.Metadata.Relational().Schema = "dbo";
});
OnModelCreating(modelBuilder);
return model;
}
示例3: CreateModel
private IModel CreateModel()
{
var model = new Model();
var builder = new ModelBuilder(model);
builder.Entity<ClrPoco>()
.PartitionAndRowKey(s => s.PartitionKey, s => s.RowKey)
.Timestamp(s => s.Timestamp);
builder.Entity("ShadowEntity", pb =>
{
pb.Property<object>("PartitionKey", true);
pb.Property<object>("RowKey", true);
pb.Property<object>("Timestamp", true);
pb.Property<object>("SomeProperty", true);
pb.Key("PartitionKey", "RowKey");
});
builder.Entity<GuidKeysPoco>()
.PartitionAndRowKey(s => s.PartitionGuid, s => s.RowGuid)
.Timestamp("Timestamp", true);
builder.Entity<IntKeysPoco>()
.PartitionAndRowKey(s => s.PartitionID, s => s.RowID);
builder.Entity<ClrPocoWithProp>(pb =>
{
pb.PartitionAndRowKey(s => s.PartitionKey, s => s.RowKey);
pb.Property(s => s.Timestamp);
pb.Property(s => s.StringProp);
pb.Property(s => s.IntProp);
});
return model;
}
示例4: CreateModel
protected virtual IModel CreateModel(
[NotNull] DbContext context,
[CanBeNull] IConventionSetBuilder conventionSetBuilder,
[NotNull] IModelValidator validator)
{
Check.NotNull(context, nameof(context));
Check.NotNull(validator, nameof(validator));
var conventionSet = CreateConventionSet(conventionSetBuilder);
var model = new Model();
model.SetProductVersion(ProductInfo.GetVersion());
var modelBuilder = new ModelBuilder(conventionSet, model);
FindSets(modelBuilder, context);
OnModelCreating(context, modelBuilder);
modelBuilder.Validate();
validator.Validate(model);
return model;
}
示例5: Get_generation_property_returns_generation_property_from_foreign_key_tree
public void Get_generation_property_returns_generation_property_from_foreign_key_tree()
{
var model = new Model();
var leftType = new EntityType("Left", model);
var leftId = leftType.AddProperty("Id", typeof(int), true);
var leftKey = leftType.AddKey(leftId);
var rightType = new EntityType("Right", model);
var rightId1 = rightType.AddProperty("Id1", typeof(int), true);
var rightId2 = rightType.AddProperty("Id2", typeof(int), true);
var rightKey = rightType.AddKey(new[] { rightId1, rightId2 });
var middleType = new EntityType("Middle", model);
var middleProperty1 = middleType.AddProperty("FK1", typeof(int), true);
var middleProperty2 = middleType.AddProperty("FK2", typeof(int), true);
var middleKey1 = middleType.AddKey(middleProperty1);
var middleFK1 = middleType.AddForeignKey(middleProperty1, leftKey, leftType);
var middleFK2 = middleType.AddForeignKey(new[] { middleProperty2, middleProperty1 }, rightKey, rightType);
var endType = new EntityType("End", model);
var endProperty = endType.AddProperty("FK", typeof(int), true);
var endFK = endType.AddForeignKey(endProperty, middleKey1, middleType);
rightId2.RequiresValueGenerator = true;
Assert.Equal(rightId2, endProperty.GetGenerationProperty());
}
示例6: Finds_existing_navigation_to_principal_and_uses_associated_FK
public virtual void Finds_existing_navigation_to_principal_and_uses_associated_FK()
{
var model = new Model();
var modelBuilder = CreateModelBuilder(model);
modelBuilder.Entity<Customer>();
modelBuilder
.Entity<Order>().Reference(c => c.Customer).InverseCollection()
.ForeignKey(c => c.CustomerId);
modelBuilder.Ignore<OrderDetails>();
modelBuilder.Ignore<CustomerDetails>();
var dependentType = model.GetEntityType(typeof(Order));
var principalType = model.GetEntityType(typeof(Customer));
var fk = dependentType.GetForeignKeys().Single();
var navigation = dependentType.GetNavigation("Customer");
var principalKey = principalType.GetKeys().Single();
var dependentKey = dependentType.GetKeys().Single();
modelBuilder.Entity<Customer>().Collection(e => e.Orders).InverseReference(e => e.Customer);
Assert.Equal(1, dependentType.GetForeignKeys().Count());
Assert.Equal("Orders", principalType.Navigations.Single().Name);
Assert.Same(fk.PrincipalKey, principalType.Navigations.Single().ForeignKey.PrincipalKey);
AssertEqual(new[] { "AlternateKey", principalKey.Properties.Single().Name, Customer.NameProperty.Name }, principalType.Properties.Select(p => p.Name));
AssertEqual(new[] { "AnotherCustomerId", fk.Properties.Single().Name, dependentKey.Properties.Single().Name }, dependentType.Properties.Select(p => p.Name));
Assert.Empty(principalType.GetForeignKeys());
Assert.Same(principalKey, principalType.GetKeys().Single());
Assert.Same(dependentKey, dependentType.GetKeys().Single());
Assert.Same(principalKey, principalType.GetPrimaryKey());
Assert.Same(dependentKey, dependentType.GetPrimaryKey());
}
示例7: Finds_existing_navigations_and_uses_associated_FK
public virtual void Finds_existing_navigations_and_uses_associated_FK()
{
var model = new Model();
var modelBuilder = CreateModelBuilder(model);
modelBuilder.Entity<Customer>();
modelBuilder
.Entity<CustomerDetails>().HasOne(d => d.Customer).WithOne(c => c.Details)
.ForeignKey<CustomerDetails>(c => c.Id);
modelBuilder.Ignore<Order>();
var dependentType = model.GetEntityType(typeof(CustomerDetails));
var principalType = model.GetEntityType(typeof(Customer));
var fk = dependentType.GetForeignKeys().Single();
var navToPrincipal = dependentType.GetNavigation(nameof(CustomerDetails.Customer));
var navToDependent = principalType.GetNavigation(nameof(Customer.Details));
var principalKey = principalType.GetKeys().Single();
var dependentKey = dependentType.GetKeys().Single();
modelBuilder.Entity<Customer>().HasOne(e => e.Details).WithOne(e => e.Customer);
Assert.Equal(1, dependentType.GetForeignKeys().Count());
Assert.Same(navToPrincipal, dependentType.Navigations.Single());
Assert.Same(navToDependent, principalType.Navigations.Single());
Assert.Same(fk.PrincipalKey, principalType.Navigations.Single().ForeignKey.PrincipalKey);
AssertEqual(new[] { "AlternateKey", principalKey.Properties.Single().Name, Customer.NameProperty.Name }, principalType.Properties.Select(p => p.Name));
AssertEqual(new[] { dependentKey.Properties.Single().Name }, dependentType.Properties.Select(p => p.Name));
Assert.Empty(principalType.GetForeignKeys());
Assert.Same(principalKey, principalType.GetKeys().Single());
Assert.Same(dependentKey, dependentType.GetKeys().Single());
Assert.Same(principalKey, principalType.GetPrimaryKey());
Assert.Same(dependentKey, dependentType.GetPrimaryKey());
}
示例8: Finds_existing_navigation_to_principal_and_uses_associated_FK
public virtual void Finds_existing_navigation_to_principal_and_uses_associated_FK()
{
var model = new Model();
var modelBuilder = CreateModelBuilder(model);
modelBuilder.Entity<Customer>();
modelBuilder
.Entity<Order>().HasOne(o => o.Customer).WithMany()
.ForeignKey(c => c.CustomerId);
modelBuilder.Ignore<OrderDetails>();
modelBuilder.Ignore<CustomerDetails>();
var dependentType = model.GetEntityType(typeof(Order));
var principalType = model.GetEntityType(typeof(Customer));
var principalKey = principalType.GetKeys().Single();
var dependentKey = dependentType.GetKeys().Single();
modelBuilder.Entity<Order>().HasOne(e => e.Customer).WithMany(e => e.Orders);
var newFk = dependentType.Navigations.Single().ForeignKey;
Assert.Equal(nameof(Order.CustomerId), newFk.Properties.Single().Name);
Assert.Same(newFk, principalType.Navigations.Single().ForeignKey);
Assert.Empty(principalType.GetForeignKeys());
Assert.Same(principalKey, principalType.GetKeys().Single());
Assert.Same(dependentKey, dependentType.GetKeys().Single());
Assert.Same(principalKey, principalType.GetPrimaryKey());
Assert.Same(dependentKey, dependentType.GetPrimaryKey());
}
示例9: Detects_shadow_entities
public virtual void Detects_shadow_entities()
{
var model = new Model();
model.AddEntityType("A");
VerifyError(CoreStrings.ShadowEntity("A"), model);
}
示例10: CreateModel
protected virtual IModel CreateModel(
[NotNull] DbContext context,
[CanBeNull] IConventionSetBuilder conventionSetBuilder,
[NotNull] IModelValidator validator)
{
Check.NotNull(context, nameof(context));
Check.NotNull(validator, nameof(validator));
var conventionSet = CreateConventionSet(conventionSetBuilder);
var model = new Model();
var productVersion = typeof(ModelSource).GetTypeInfo().Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
model[CoreAnnotationNames.ProductVersionAnnotation] = productVersion;
var modelBuilder = new ModelBuilder(conventionSet, model);
FindSets(modelBuilder, context);
OnModelCreating(context, modelBuilder);
modelBuilder.Validate();
validator.Validate(model);
return model;
}
示例11: CreateForeignKey
private ForeignKey CreateForeignKey()
{
var model = new Model();
var entityType = model.AddEntityType("E");
var property = entityType.AddProperty("p", typeof(int), shadowProperty: true);
var key = entityType.SetPrimaryKey(property);
return new ForeignKey(new[] { property }, key);
}
示例12: Can_set_model
public void Can_set_model()
{
var sequence = new Sequence("Foo");
var model = new Model();
sequence.Model = model;
Assert.Same(model, sequence.Model);
}
示例13: Model
public virtual void ForeignKeyAttribute_does_not_set_foreign_key_properties_when_names_on_property_and_navigation_do_not_match()
{
var model = new Model();
var modelBuilder = CreateModelBuilder(model);
modelBuilder.Entity<Author>();
Assert.Equal("AuthorId", model.GetEntityType(typeof(AuthorDetails)).FindNavigation("Author").ForeignKey.Properties.First().Name);
}
示例14: Model_can_be_set_explicitly_in_options
public void Model_can_be_set_explicitly_in_options()
{
var model = new Model();
var optionsBuilder = new DbContextOptionsBuilder().UseModel(model);
Assert.Same(model, optionsBuilder.Options.FindExtension<CoreOptionsExtension>().Model);
}
示例15: Detects_a_null_primary_key
public virtual void Detects_a_null_primary_key()
{
var model = new Model();
var entityType = model.AddEntityType(typeof(A));
var property = entityType.AddProperty("Id", typeof(int));
VerifyError(CoreStrings.EntityRequiresKey(typeof(A).FullName), model);
}