本文整理汇总了C#中Microsoft.Data.Entity.Metadata.Model.AddEntityType方法的典型用法代码示例。如果您正苦于以下问题:C# Model.AddEntityType方法的具体用法?C# Model.AddEntityType怎么用?C# Model.AddEntityType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Data.Entity.Metadata.Model
的用法示例。
在下文中一共展示了Model.AddEntityType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Circular_inheritance_should_throw
public void Circular_inheritance_should_throw()
{
var model = new Model();
// A
// / \
// B C
// \
// D
var a = model.AddEntityType(typeof(A).Name);
var b = model.AddEntityType(typeof(B).Name);
var c = model.AddEntityType(typeof(C).Name);
var d = model.AddEntityType(typeof(D).Name);
b.BaseType = a;
c.BaseType = a;
d.BaseType = c;
Assert.Equal(
Strings.CircularInheritance(a, a),
Assert.Throws<InvalidOperationException>(() => a.BaseType = a).Message);
Assert.Equal(
Strings.CircularInheritance(a, b),
Assert.Throws<InvalidOperationException>(() => a.BaseType = b).Message);
Assert.Equal(
Strings.CircularInheritance(a, d),
Assert.Throws<InvalidOperationException>(() => a.BaseType = d).Message);
}
示例2: Detects_foreign_key_cycles
public virtual void Detects_foreign_key_cycles()
{
var model = new Model();
var entityA = model.AddEntityType(typeof(A));
var keyA = CreateKey(entityA);
var entityB = model.AddEntityType(typeof(B));
var keyB = CreateKey(entityB);
CreateForeignKey(keyA, keyB);
CreateForeignKey(keyB, keyA);
VerifyError(Strings.CircularDependency("'A' {'P0'} -> 'B' {'P0'}, 'B' {'P0'} -> 'A' {'P0'}"), model);
}
示例3: Throws_when_referenced_key_not_on_referenced_entity
public void Throws_when_referenced_key_not_on_referenced_entity()
{
var model = new Model();
var principalEntityType = model.AddEntityType("R");
var dependentEntityType = model.AddEntityType("D");
var fk = dependentEntityType.AddProperty("Fk", typeof(int), shadowProperty: true);
var principalKey = dependentEntityType.SetPrimaryKey(fk);
Assert.Throws<ArgumentException>(() =>
new ForeignKey(new[] { fk }, principalKey, principalEntityType));
}
示例4: Passes_on_escapable_foreign_key_cycles_not_starting_at_hub
public virtual void Passes_on_escapable_foreign_key_cycles_not_starting_at_hub()
{
var model = new Model();
var entityA = model.AddEntityType(typeof(A));
var keyA1 = CreateKey(entityA);
var keyA2 = CreateKey(entityA, startingPropertyIndex: 1, propertyCount: 2);
var entityB = model.AddEntityType(typeof(B));
var keyB1 = CreateKey(entityB);
var keyB2 = CreateKey(entityB, startingPropertyIndex: 0, propertyCount: 2);
CreateForeignKey(keyA1, keyB1);
CreateForeignKey(keyB1, keyA1);
CreateForeignKey(keyB2, keyA2);
Validate(model);
}
示例5: Detects_shadow_entities
public virtual void Detects_shadow_entities()
{
var model = new Model();
model.AddEntityType("A");
VerifyError(CoreStrings.ShadowEntity("A"), model);
}
示例6: Properties_on_base_type_should_be_inherited
public void Properties_on_base_type_should_be_inherited()
{
var model = new Model();
// A
// / \
// B C
var a = model.AddEntityType(typeof(A));
a.AddProperty("G", typeof(string));
a.AddProperty("E", typeof(string));
var b = model.AddEntityType(typeof(B));
b.AddProperty("H", typeof(string));
b.AddProperty("F", typeof(string));
var c = model.AddEntityType(typeof(C));
c.AddProperty("H", typeof(string), true);
c.AddProperty("I", typeof(string), true);
Assert.Equal(new[] { "E", "G" }, a.Properties.Select(p => p.Name).ToArray());
Assert.Equal(new[] { "F", "H" }, b.Properties.Select(p => p.Name).ToArray());
Assert.Equal(new[] { "H", "I" }, c.Properties.Select(p => p.Name).ToArray());
b.BaseType = a;
c.BaseType = a;
Assert.Equal(new[] { "E", "G" }, a.Properties.Select(p => p.Name).ToArray());
Assert.Equal(new[] { "E", "G", "F", "H" }, b.Properties.Select(p => p.Name).ToArray());
Assert.Equal(new[] { "E", "G", "H", "I" }, c.Properties.Select(p => p.Name).ToArray());
Assert.Equal(new[] { 0, 1, 2, 3 }, b.Properties.Select(p => p.Index));
Assert.Equal(new[] { 0, 1, 2, 3 }, c.Properties.Select(p => p.Index));
}
示例7: 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);
}
示例8: 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);
}
示例9: Detects_a_non_shadow_property_that_doesnt_match_the_CLR_property_type
public virtual void Detects_a_non_shadow_property_that_doesnt_match_the_CLR_property_type()
{
var model = new Model();
var entityType = model.AddEntityType(typeof(A));
var property = entityType.AddProperty("P0", typeof(string));
property.IsShadowProperty = false;
VerifyError(Strings.PropertyWrongClrType("P0", typeof(A).FullName), model);
}
示例10: Detects_shadow_keys
public virtual void Detects_shadow_keys()
{
var model = new Model();
var entityType = model.AddEntityType("E");
var keyProperty = entityType.AddProperty("Id", typeof(int), shadowProperty: true);
entityType.AddKey(keyProperty);
VerifyWarning(Strings.ShadowKey("{'Id'}", "E", "{'Id'}"), model);
}
示例11: CreateForeignKey
private ForeignKey CreateForeignKey()
{
var model = new Model();
var entityType = model.AddEntityType("E");
var idProperty = entityType.AddProperty("id", typeof(int));
var key = entityType.SetPrimaryKey(idProperty);
var fkProperty = entityType.AddProperty("p", typeof(int));
return entityType.AddForeignKey(fkProperty, key, entityType);
}
示例12: CreateModel
private static Model CreateModel(bool generateValues = true)
{
var model = new Model();
var entityType = model.AddEntityType("Led");
entityType.AddProperty("Zeppelin", typeof(Guid));
entityType.AddProperty("Stairway", typeof(Guid)).RequiresValueGenerator = generateValues;
return model;
}
示例13: BuildModel
protected override Model BuildModel()
{
var model = new Model();
var entityType1 = new EntityType("SomeEntity");
model.AddEntityType(entityType1);
var key1 = entityType1.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false);
key1.ValueGenerationOnSave = ValueGenerationOnSave.WhenInserting;
key1.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;
entityType1.SetKey(key1);
entityType1.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: true);
var entityType2 = new EntityType("SomeDependentEntity");
model.AddEntityType(entityType2);
var key2a = entityType2.AddProperty("Id1", typeof(int), shadowProperty: true, concurrencyToken: false);
var key2b = entityType2.AddProperty("Id2", typeof(string), shadowProperty: true, concurrencyToken: false);
entityType2.SetKey(key2a, key2b);
var fk = entityType2.AddProperty("SomeEntityId", typeof(int), shadowProperty: true, concurrencyToken: false);
entityType2.AddForeignKey(entityType1.GetKey(), new[] { fk });
var justAProperty = entityType2.AddProperty("JustAProperty", typeof(int), shadowProperty: true, concurrencyToken: false);
justAProperty.ValueGenerationOnSave = ValueGenerationOnSave.WhenInserting;
justAProperty.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;
var entityType3 = new EntityType(typeof(FullNotificationEntity));
model.AddEntityType(entityType3);
entityType3.SetKey(entityType3.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));
entityType3.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: true);
var entityType4 = new EntityType(typeof(ChangedOnlyEntity));
model.AddEntityType(entityType4);
entityType4.SetKey(entityType4.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));
entityType4.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: true);
var entityType5 = new EntityType("SomeMoreDependentEntity");
model.AddEntityType(entityType5);
var key5 = entityType5.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false);
entityType5.SetKey(key5);
var fk5a = entityType5.AddProperty("Fk1", typeof(int), shadowProperty: true, concurrencyToken: false);
var fk5b = entityType5.AddProperty("Fk2", typeof(string), shadowProperty: true, concurrencyToken: false);
entityType5.AddForeignKey(entityType2.GetKey(), new[] { fk5a, fk5b });
return model;
}
示例14: Detects_a_non_shadow_property_that_doesnt_match_a_CLR_property
public virtual void Detects_a_non_shadow_property_that_doesnt_match_a_CLR_property()
{
var model = new Model();
var entityType = model.AddEntityType(typeof(A));
var property = entityType.AddProperty("Id1", typeof(int));
property.IsShadowProperty = false;
entityType.SetPrimaryKey(property);
VerifyError(CoreStrings.NoClrProperty("Id1", typeof(A).FullName), model);
}
示例15: Detects_self_referencing_properties
public virtual void Detects_self_referencing_properties()
{
var model = new Model();
var entityA = model.AddEntityType(typeof(A));
var keyA = CreateKey(entityA);
CreateForeignKey(keyA, keyA);
VerifyError(Strings.CircularDependency("'A' {'P0'} -> 'A' {'P0'}"), model);
}