当前位置: 首页>>代码示例>>C#>>正文


C# Model.AddProperty方法代码示例

本文整理汇总了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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:13,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:19,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:20,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:11,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:16,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:10,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:9,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:23,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:11,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:10,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:11,代码来源:PropertyTest.cs

示例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;
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:8,代码来源:SqlServerValueGeneratorCacheTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:13,代码来源:PropertyTest.cs

示例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));
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:11,代码来源:PropertyTest.cs

示例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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:9,代码来源:PropertyTest.cs


注:本文中的Microsoft.Data.Entity.Metadata.Model.AddProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。