本文整理汇总了C#中Microsoft.Data.Entity.Metadata.Model.AddProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Model.AddProperty方法的具体用法?C# Model.AddProperty怎么用?C# Model.AddProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Data.Entity.Metadata.Model
的用法示例。
在下文中一共展示了Model.AddProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setting_ClrType_throws_when_referenced
public void Setting_ClrType_throws_when_referenced()
{
var entityType = new Model().AddEntityType(typeof(object));
var principalProperty = entityType.AddProperty("Kake");
var key = entityType.AddKey(principalProperty);
var dependentProperty = entityType.AddProperty("Alaska");
entityType.AddForeignKey(dependentProperty, key, entityType);
Assert.Equal(CoreStrings.PropertyClrTypeCannotBeChangedWhenReferenced("Kake", "{'Alaska'}", "object"),
Assert.Throws<InvalidOperationException>(() =>
principalProperty.ClrType = typeof(int)).Message);
Assert.Equal(typeof(string), ((IProperty)principalProperty).ClrType);
}
示例2: Model
public void Default_nullability_of_property_is_based_on_nullability_of_CLR_type_and_property_being_part_of_primary_key()
{
var entityType = new Model().AddEntityType(typeof(object));
var stringProperty = entityType.AddProperty("stringName", typeof(string));
var nullableIntProperty = entityType.AddProperty("nullableIntName", typeof(int?));
var intProperty = entityType.AddProperty("intName", typeof(int));
Assert.Null(stringProperty.IsNullable);
Assert.True(((IProperty)stringProperty).IsNullable);
Assert.Null(stringProperty.IsNullable);
Assert.True(((IProperty)nullableIntProperty).IsNullable);
Assert.Null(intProperty.IsNullable);
Assert.False(((IProperty)intProperty).IsNullable);
entityType.SetPrimaryKey(stringProperty);
Assert.Null(stringProperty.IsNullable);
Assert.False(((IProperty)stringProperty).IsNullable);
}
示例3: Property_nullability_can_be_mutated
public void Property_nullability_can_be_mutated()
{
var entityType = new Model().AddEntityType(typeof(object));
var stringProperty = entityType.AddProperty("Name", typeof(string));
var intProperty = entityType.AddProperty("Id", typeof(int));
stringProperty.IsNullable = false;
Assert.False(stringProperty.IsNullable.Value);
Assert.Null(intProperty.IsNullable);
stringProperty.IsNullable = true;
intProperty.IsNullable = false;
Assert.True(stringProperty.IsNullable.Value);
Assert.False(intProperty.IsNullable.Value);
stringProperty.IsNullable = null;
intProperty.IsNullable = null;
Assert.Null(stringProperty.IsNullable);
Assert.Null(intProperty.IsNullable);
}
示例4: Can_set_ClrType
public void Can_set_ClrType()
{
var entityType = new Model().AddEntityType(typeof(object));
var property = entityType.AddProperty("Kake");
Assert.Null(property.ClrType);
Assert.Equal(typeof(string), ((IProperty)property).ClrType);
property.ClrType = typeof(int);
Assert.Equal(typeof(int), property.ClrType);
}
示例5: Can_mark_property_as_concurrency_token
public void Can_mark_property_as_concurrency_token()
{
var entityType = new Model().AddEntityType(typeof(object));
var property = entityType.AddProperty("Name");
property.ClrType = typeof(string);
property.IsShadowProperty = false;
property.IsConcurrencyToken = true;
Assert.True(property.IsConcurrencyToken.Value);
property.IsConcurrencyToken = false;
Assert.False(property.IsConcurrencyToken.Value);
property.IsConcurrencyToken = null;
Assert.Null(property.IsConcurrencyToken);
}
示例6: Can_set_sentinel_for_non_nullable_property
public void Can_set_sentinel_for_non_nullable_property()
{
var entityType = new Model().AddEntityType(typeof(object));
var property = entityType.AddProperty("Name", typeof(int));
property.IsShadowProperty = false;
property.SentinelValue = -1;
Assert.Equal(-1, property.SentinelValue);
Assert.Equal(-1, ((IProperty)property).SentinelValue);
}
示例7: Non_nullable_property_has_CLR_default_sentinel_by_default
public void Non_nullable_property_has_CLR_default_sentinel_by_default()
{
var entityType = new Model().AddEntityType(typeof(object));
var property = entityType.AddProperty("Name", typeof(int));
property.IsShadowProperty = false;
Assert.Null(property.SentinelValue);
Assert.Equal(0, ((IProperty)property).SentinelValue);
}
示例8: Can_get_and_set_property_and_shadow_index_for_shadow_property
public void Can_get_and_set_property_and_shadow_index_for_shadow_property()
{
var entityType = new Model().AddEntityType(typeof(object));
var property = entityType.AddProperty("Kake", typeof(int));
property.IsShadowProperty = true;
Assert.Equal(0, property.Index);
Assert.Equal(0, property.GetShadowIndex());
property.Index = 1;
property.SetShadowIndex(2);
Assert.Equal(1, property.Index);
Assert.Equal(2, property.GetShadowIndex());
Assert.Equal(
"value",
Assert.Throws<ArgumentOutOfRangeException>(() => property.Index = -1).ParamName);
Assert.Equal(
"index",
Assert.Throws<ArgumentOutOfRangeException>(() => property.SetShadowIndex(-1)).ParamName);
}
示例9: Property_can_be_marked_as_read_only_always
public void Property_can_be_marked_as_read_only_always()
{
var entityType = new Model().AddEntityType(typeof(object));
var property = entityType.AddProperty("Name", typeof(string));
property.IsShadowProperty = false;
property.IsReadOnlyBeforeSave = true;
property.IsReadOnlyAfterSave = true;
Assert.True(property.IsReadOnlyBeforeSave.Value);
Assert.True(property.IsReadOnlyAfterSave.Value);
}
示例10: Properties_which_are_part_of_primary_key_cannot_be_made_nullable
public void Properties_which_are_part_of_primary_key_cannot_be_made_nullable()
{
var entityType = new Model().AddEntityType(typeof(object));
var stringProperty = entityType.AddProperty("Name", typeof(string));
stringProperty.DeclaringEntityType.SetPrimaryKey(stringProperty);
Assert.Equal(
CoreStrings.CannotBeNullablePK("Name", "object"),
Assert.Throws<InvalidOperationException>(() => stringProperty.IsNullable = true).Message);
}
示例11: Property_is_read_write_by_default
public void Property_is_read_write_by_default()
{
var entityType = new Model().AddEntityType(typeof(object));
var property = entityType.AddProperty("Name", typeof(string));
property.IsShadowProperty = false;
Assert.Null(property.IsReadOnlyAfterSave);
Assert.False(((IProperty)property).IsReadOnlyAfterSave);
Assert.Null(property.IsReadOnlyBeforeSave);
Assert.False(((IProperty)property).IsReadOnlyBeforeSave);
}
示例12: CreateProperty
private static Property CreateProperty()
{
var entityType = new Model().AddEntityType("MyType");
var property = entityType.AddProperty("MyProperty", typeof(string));
entityType.SqlServer().TableName = "MyTable";
return property;
}
示例13: Property_nullability_is_changed_if_property_made_part_of_primary_key
public void Property_nullability_is_changed_if_property_made_part_of_primary_key()
{
var entityType = new Model().AddEntityType(typeof(object));
var stringProperty = entityType.AddProperty("Name", typeof(string));
stringProperty.IsNullable = true;
Assert.True(stringProperty.IsNullable.Value);
stringProperty.DeclaringEntityType.SetPrimaryKey(stringProperty);
Assert.Null(stringProperty.IsNullable);
Assert.False(((IProperty)stringProperty).IsNullable);
}
示例14: IsSentinelValue_on_non_nullable_propertyalways_returns_true_for_null_or_sentinel
public void IsSentinelValue_on_non_nullable_propertyalways_returns_true_for_null_or_sentinel()
{
var entityType = new Model().AddEntityType(typeof(object));
var property = entityType.AddProperty("Name", typeof(int));
property.IsShadowProperty = false;
property.SentinelValue = -1;
Assert.True(property.IsSentinelValue(null));
Assert.True(property.IsSentinelValue(-1));
Assert.False(property.IsSentinelValue(0));
}
示例15: Property_is_not_concurrency_token_by_default
public void Property_is_not_concurrency_token_by_default()
{
var entityType = new Model().AddEntityType(typeof(object));
var property = entityType.AddProperty("Name", typeof(string));
property.IsShadowProperty = false;
Assert.Null(property.IsConcurrencyToken);
Assert.False(((IProperty)property).IsConcurrencyToken);
}