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


C# Model.AddProperty方法代码示例

本文整理汇总了C#中Microsoft.EntityFrameworkCore.Metadata.Internal.Model.AddProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Model.AddProperty方法的具体用法?C# Model.AddProperty怎么用?C# Model.AddProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.EntityFrameworkCore.Metadata.Internal.Model的用法示例。


在下文中一共展示了Model.AddProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Default_nullability_of_property_is_based_on_nullability_of_CLR_type

        public void Default_nullability_of_property_is_based_on_nullability_of_CLR_type()
        {
            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.True(stringProperty.IsNullable);
            Assert.True(nullableIntProperty.IsNullable);
            Assert.False(intProperty.IsNullable);
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:11,代码来源:PropertyTest.cs

示例2: Can_read_nulls

        public void Can_read_nulls()
        {
            var entityType = new Model().AddEntityType(typeof(SomeEntity));
            entityType.AddProperty(SomeEntity.FooProperty);
            entityType.AddProperty(SomeEntity.GooProperty);
            entityType.AddProperty(SomeEntity.IdProperty);

            var factory = GetMaterializer(new EntityMaterializerSource(new MemberMapper(new FieldMatcher())), entityType);

            var entity = (SomeEntity)factory(new ValueBuffer(new object[] { null, null, 77 }));

            Assert.Equal(77, entity.Id);
            Assert.Null(entity.Foo);
            Assert.Null(entity.Goo);
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:15,代码来源:EntityMaterializerSourceTest.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);
            Assert.False(intProperty.IsNullable);

            stringProperty.IsNullable = true;
            intProperty.IsNullable = false;
            Assert.True(stringProperty.IsNullable);
            Assert.False(intProperty.IsNullable);
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:15,代码来源:PropertyTest.cs

示例4: Delegate_getter_is_returned_for_IProperty_property

        public void Delegate_getter_is_returned_for_IProperty_property()
        {
            var entityType = new Model().AddEntityType(typeof(Customer));
            var idProperty = entityType.AddProperty("Id", typeof(int), shadow: false);

            Assert.Equal(7, new ClrPropertyGetterFactory().Create(idProperty).GetClrValue(new Customer { Id = 7 }));
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:7,代码来源:ClrPropertyGetterFactoryTest.cs

示例5: Constructor_throws_when_principal_and_depedent_property_count_do_not_match

        public void Constructor_throws_when_principal_and_depedent_property_count_do_not_match()
        {
            var dependentEntityType = new Model().AddEntityType("D");
            var principalEntityType = new Model().AddEntityType("P");

            var dependentProperty1 = dependentEntityType.AddProperty("P1", typeof(int));
            var dependentProperty2 = dependentEntityType.AddProperty("P2", typeof(int));

            var idProperty = principalEntityType.AddProperty("Id", typeof(int));
            principalEntityType.GetOrSetPrimaryKey(idProperty);

            Assert.Equal(
                CoreStrings.ForeignKeyCountMismatch("{'P1', 'P2'}", "D", "{'Id'}", "P"),
                Assert.Throws<InvalidOperationException>(
                    () => dependentEntityType.AddForeignKey(new[] { dependentProperty1, dependentProperty2 }, principalEntityType.FindPrimaryKey(), principalEntityType)).Message);
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:16,代码来源:ForeignKeyTest.cs

示例6: Can_set_ClrType

        public void Can_set_ClrType()
        {
            var entityType = new Model().AddEntityType(typeof(object));
            var property = entityType.AddProperty("Kake", typeof(string));

            Assert.Equal(typeof(string), property.ClrType);
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:7,代码来源:PropertyTest.cs

示例7: M_underscore_matching_field_is_not_used_if_type_is_not_compatible

        public void M_underscore_matching_field_is_not_used_if_type_is_not_compatible()
        {
            var entityType = new Model().AddEntityType(typeof(TheDarkSideOfTheMoon));
            var property = entityType.AddProperty("SpeakToMe", typeof(int), shadow: false);
            var propertyInfo = entityType.ClrType.GetAnyProperty("SpeakToMe");
            var fields = propertyInfo.DeclaringType.GetRuntimeFields().ToDictionary(f => f.Name);

            Assert.Null(new FieldMatcher().TryMatchFieldName(property, propertyInfo, fields));
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:9,代码来源:FieldMatcherTest.cs

示例8: Throws_if_no_match_found_and_no_property_setter

        public void Throws_if_no_match_found_and_no_property_setter()
        {
            var entityType = new Model().AddEntityType(typeof(TheDarkSide));
            var property = entityType.AddProperty(TheDarkSide.TimeProperty);

            Assert.Equal(
                CoreStrings.NoFieldOrSetter(typeof(TheDarkSide).FullName, "Time"),
                Assert.Throws<InvalidOperationException>(
                    () => new MemberMapper(new FieldMatcher()).MapPropertiesToMembers(entityType)).Message);
        }
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:10,代码来源:MemberMapperTest.cs

示例9: Throws_if_annotated_field_name_is_not_found

        public void Throws_if_annotated_field_name_is_not_found()
        {
            var entityType = new Model().AddEntityType(typeof(TheDarkSide));
            var property = entityType.AddProperty(TheDarkSide.SpeakToMeProperty);
            property["BackingField"] = "_speakToMe";

            Assert.Equal(
                CoreStrings.MissingBackingField(typeof(TheDarkSide).FullName, "SpeakToMe", "_speakToMe"),
                Assert.Throws<InvalidOperationException>(
                    () => new MemberMapper(new FieldMatcher()).MapPropertiesToMembers(entityType)).Message);
        }
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:11,代码来源:MemberMapperTest.cs

示例10: Throws_if_annotated_field_if_types_not_compatible

        public void Throws_if_annotated_field_if_types_not_compatible()
        {
            var entityType = new Model().AddEntityType(typeof(TheDarkSide));
            var property = entityType.AddProperty(TheDarkSide.SpeakToMeProperty);
            property["BackingField"] = "_badFieldForSpeak";

            Assert.Equal(
                CoreStrings.BadBackingFieldType("_badFieldForSpeak", typeof(string).Name, typeof(TheDarkSide).FullName, "SpeakToMe", typeof(int).Name),
                Assert.Throws<InvalidOperationException>(
                    () => new MemberMapper(new FieldMatcher()).MapPropertiesToMembers(entityType)).Message);
        }
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:11,代码来源:MemberMapperTest.cs

示例11: Delegate_setter_can_set_nullable_property

        public void Delegate_setter_can_set_nullable_property()
        {
            var entityType = new Model().AddEntityType(typeof(Customer));
            var idProperty = entityType.AddProperty(Customer.OptionalIntProperty);

            var customer = new Customer { Id = 7 };

            new ClrPropertySetterFactory().Create(idProperty).SetClrValue(customer, 3);

            Assert.Equal(3, customer.OptionalInt);
        }
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:11,代码来源:ClrPropertySetterFactoryTest.cs

示例12: Field_name_match_is_used_in_preference_to_property_setter

        public void Field_name_match_is_used_in_preference_to_property_setter()
        {
            var entityType = new Model().AddEntityType(typeof(TheDarkSide));
            var property = entityType.AddProperty(TheDarkSide.BreatheProperty);

            var mapping = new MemberMapper(new FieldMatcher()).MapPropertiesToMembers(entityType).Single();

            Assert.Same(property, mapping.Item1);
            Assert.IsAssignableFrom<FieldInfo>(mapping.Item2);
            Assert.Equal("_breathe", mapping.Item2.Name);
        }
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:11,代码来源:MemberMapperTest.cs

示例13: FieldMatchTest

        private static void FieldMatchTest(string propertyName, string fieldName)
        {
            var entityType = new Model().AddEntityType(typeof(TheDarkSideOfTheMoon));
            var property = entityType.AddProperty(propertyName, typeof(int), shadow: false);
            var propertyInfo = entityType.ClrType.GetAnyProperty(propertyName);
            var fields = propertyInfo.DeclaringType.GetRuntimeFields().ToDictionary(f => f.Name);

            var matchedField = new FieldMatcher().TryMatchFieldName(property, propertyInfo, fields);

            Assert.Equal(fieldName, matchedField.Name);
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:11,代码来源:FieldMatcherTest.cs

示例14: Can_create_materializer_for_entity_with_fields

        public void Can_create_materializer_for_entity_with_fields()
        {
            var entityType = new Model().AddEntityType(typeof(SomeEntityWithFields));
            entityType.AddProperty(SomeEntityWithFields.EnumProperty);
            entityType.AddProperty(SomeEntityWithFields.FooProperty);
            entityType.AddProperty(SomeEntityWithFields.GooProperty);
            entityType.AddProperty(SomeEntityWithFields.IdProperty);
            entityType.AddProperty(SomeEntityWithFields.MaybeEnumProperty);

            var factory = GetMaterializer(new EntityMaterializerSource(new MemberMapper(new FieldMatcher())), entityType);

            var gu = Guid.NewGuid();
            var entity = (SomeEntityWithFields)factory(new ValueBuffer(new object[] { SomeEnum.EnumValue, "Fu", gu, 77, null }));

            Assert.Equal(77, entity.Id);
            Assert.Equal("Fu", entity.Foo);
            Assert.Equal(gu, entity.Goo);
            Assert.Equal(SomeEnum.EnumValue, entity.Enum);
            Assert.Null(entity.MaybeEnum);
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:20,代码来源:EntityMaterializerSourceTest.cs

示例15: Delegate_setter_can_set_reference_type_property

        public void Delegate_setter_can_set_reference_type_property()
        {
            var entityType = new Model().AddEntityType(typeof(Customer));
            var idProperty = entityType.AddProperty(Customer.ContentProperty);

            var customer = new Customer { Id = 7 };

            new ClrPropertySetterFactory().Create(idProperty).SetClrValue(customer, "MyString");

            Assert.Equal("MyString", customer.Content);
        }
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:11,代码来源:ClrPropertySetterFactoryTest.cs


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