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


C# EntityType.GetProperty方法代码示例

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


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

示例1: Members_check_arguments

        public void Members_check_arguments()
        {
            Assert.Equal(
                "type",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => new EntityType((Type)null)).ParamName);

            Assert.Equal(
                "name",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => new EntityType((string)null)).ParamName);

            var entityType = new EntityType(typeof(Random));

            Assert.Equal(
                "propertyInfo",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => entityType.AddProperty((PropertyInfo)null)).ParamName);

            Assert.Equal(
                "property",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => entityType.RemoveProperty(null)).ParamName);

            Assert.Equal(
                Strings.FormatArgumentIsEmpty("name"),
                Assert.Throws<ArgumentException>(() => entityType.TryGetProperty("")).Message);

            Assert.Equal(
                Strings.FormatArgumentIsEmpty("name"),
                Assert.Throws<ArgumentException>(() => entityType.GetProperty("")).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:32,代码来源:EntityTypeTest.cs

示例2: It_adds_etag

 public void It_adds_etag()
 {
     var entityType = new EntityType("TestType");
     _convention.Apply(entityType);
     var etagProp = entityType.GetProperty("ETag");
     Assert.NotNull(etagProp);
     Assert.False(etagProp.IsClrProperty);
     Assert.True(etagProp.IsConcurrencyToken);
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:9,代码来源:ETagConventionTest.cs

示例3: It_does_not_overwrite_etag_prop

        public void It_does_not_overwrite_etag_prop()
        {
            var entityType = new EntityType("TestType");
            entityType.AddProperty("ETag", typeof(int), false, false);

            _convention.Apply(entityType);
            var etagProp = entityType.GetProperty("ETag");
            Assert.NotNull(etagProp);
            Assert.True(etagProp.IsClrProperty);
            Assert.False(etagProp.IsConcurrencyToken);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:11,代码来源:ETagConventionTest.cs

示例4: Shadow_properties_have_CLR_flag_set_to_false

        public void Shadow_properties_have_CLR_flag_set_to_false()
        {
            var entityType = new EntityType(typeof(Customer), new Model());

            entityType.GetOrAddProperty(Customer.NameProperty);
            entityType.GetOrAddProperty("Id", typeof(int));
            entityType.GetOrAddProperty("Mane", typeof(int), shadowProperty: true);

            Assert.False(entityType.GetProperty("Name").IsShadowProperty);
            Assert.False(entityType.GetProperty("Id").IsShadowProperty);
            Assert.True(entityType.GetProperty("Mane").IsShadowProperty);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:12,代码来源:EntityTypeTest.cs

示例5: Can_add_update_delete_end_to_end_using_partial_shadow_state

        public async Task Can_add_update_delete_end_to_end_using_partial_shadow_state()
        {
            var model = new Model();

            var customerType = new EntityType(typeof(Customer));
            customerType.SetKey(customerType.AddProperty("Id", typeof(int), shadowProperty: false, concurrencyToken: false));
            customerType.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: false);

            model.AddEntityType(customerType);

            var options = new DbContextOptions()
                .UseModel(model)
                .UseInMemoryStore();

            var customer = new Customer { Id = 42 };

            using (var context = new DbContext(options))
            {
                context.Add(customer);

                // TODO: Better API for shadow state access
                var customerEntry = context.ChangeTracker.Entry(customer).StateEntry;
                customerEntry[customerType.GetProperty("Name")] = "Daenerys";

                await context.SaveChangesAsync();

                customerEntry[customerType.GetProperty("Name")] = "Changed!";
            }

            using (var context = new DbContext(options))
            {
                var customerFromStore = context.Set<Customer>().Single();

                Assert.Equal(42, customerFromStore.Id);
                Assert.Equal(
                    "Daenerys",
                    (string)context.ChangeTracker.Entry(customerFromStore).Property("Name").CurrentValue);
            }

            using (var context = new DbContext(options))
            {
                var customerEntry = context.ChangeTracker.Entry(customer).StateEntry;
                customerEntry[customerType.GetProperty("Name")] = "Daenerys Targaryen";

                context.Update(customer);

                await context.SaveChangesAsync();
            }

            using (var context = new DbContext(options))
            {
                var customerFromStore = context.Set<Customer>().Single();

                Assert.Equal(42, customerFromStore.Id);
                Assert.Equal(
                    "Daenerys Targaryen",
                    (string)context.ChangeTracker.Entry(customerFromStore).Property("Name").CurrentValue);
            }

            using (var context = new DbContext(options))
            {
                context.Delete(customer);

                await context.SaveChangesAsync();
            }

            using (var context = new DbContext(options))
            {
                Assert.Equal(0, context.Set<Customer>().Count());
            }
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:71,代码来源:ShadowStateUpdateTest.cs

示例6: Shadow_properties_have_CLR_flag_set_to_false

        public void Shadow_properties_have_CLR_flag_set_to_false()
        {
            var entityType = new EntityType(typeof(Customer));

            entityType.AddProperty(Customer.NameProperty);
            entityType.AddProperty("Id", typeof(int));
            entityType.AddProperty("Mane", typeof(int), shadowProperty: true, concurrencyToken: false);

            Assert.True(entityType.GetProperty("Name").IsClrProperty);
            Assert.True(entityType.GetProperty("Id").IsClrProperty);
            Assert.False(entityType.GetProperty("Mane").IsClrProperty);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:12,代码来源:EntityTypeTest.cs

示例7: FK_properties_are_marked_as_requiring_original_values

        public void FK_properties_are_marked_as_requiring_original_values()
        {
            var entityType = new EntityType(typeof(FullNotificationEntity), new Model());
            entityType.GetOrSetPrimaryKey(entityType.GetOrAddProperty("Id", typeof(int)));

            Assert.Equal(-1, entityType.GetProperty("Id").GetOriginalValueIndex());

            entityType.GetOrAddForeignKey(new[] { entityType.GetOrAddProperty("Id", typeof(int)) }, entityType.GetPrimaryKey());

            Assert.Equal(0, entityType.GetProperty("Id").GetOriginalValueIndex());
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:11,代码来源:EntityTypeTest.cs

示例8: Can_add_update_delete_end_to_end_using_only_shadow_state

        public async Task Can_add_update_delete_end_to_end_using_only_shadow_state()
        {
            var model = new Model();

            var customerType = new EntityType("Customer");
            customerType.SetKey(customerType.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));
            customerType.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: false);

            model.AddEntityType(customerType);

            var options = new DbContextOptions()
                .UseModel(model)
                .UseInMemoryStore();

            using (var context = new DbContext(options))
            {
                // TODO: Better API for shadow state access
                var customerEntry = context.ChangeTracker.StateManager.CreateNewEntry(customerType);
                customerEntry[customerType.GetProperty("Id")] = 42;
                customerEntry[customerType.GetProperty("Name")] = "Daenerys";

                await customerEntry.SetEntityStateAsync(EntityState.Added);

                await context.SaveChangesAsync();

                customerEntry[customerType.GetProperty("Name")] = "Changed!";
            }

            // TODO: Fix this when we can query shadow entities
            // var customerFromStore = await inMemoryDataStore.Read(customerType).SingleAsync();
            //
            // Assert.Equal(new object[] { 42, "Daenerys" }, customerFromStore);

            using (var context = new DbContext(options))
            {
                var customerEntry = context.ChangeTracker.StateManager.CreateNewEntry(customerType);
                customerEntry[customerType.GetProperty("Id")] = 42;
                customerEntry[customerType.GetProperty("Name")] = "Daenerys Targaryen";

                await customerEntry.SetEntityStateAsync(EntityState.Modified);

                await context.SaveChangesAsync();
            }

            // TODO: Fix this when we can query shadow entities
            // customerFromStore = await inMemoryDataStore.Read(customerType).SingleAsync();
            // 
            // Assert.Equal(new object[] { 42, "Daenerys Targaryen" }, customerFromStore);

            using (var context = new DbContext(options))
            {
                var customerEntry = context.ChangeTracker.StateManager.CreateNewEntry(customerType);
                customerEntry[customerType.GetProperty("Id")] = 42;

                await customerEntry.SetEntityStateAsync(EntityState.Deleted);

                await context.SaveChangesAsync();
            }

            // TODO: Fix this when we can query shadow entities
            // Assert.Equal(0, await inMemoryDataStore.Read(customerType).CountAsync());
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:62,代码来源:ShadowStateUpdateTest.cs

示例9: Indexes_are_rebuilt_when_more_properties_added_or_relevant_state_changes

        public void Indexes_are_rebuilt_when_more_properties_added_or_relevant_state_changes()
        {
            var entityType = new EntityType(typeof(FullNotificationEntity), new Model());

            var nameProperty = entityType.GetOrAddProperty("Name", typeof(string));
            entityType.GetOrAddProperty("Id", typeof(int), shadowProperty: true).IsConcurrencyToken = true;

            Assert.Equal(0, entityType.GetProperty("Id").Index);
            Assert.Equal(1, entityType.GetProperty("Name").Index);

            Assert.Equal(0, entityType.GetProperty("Id").GetShadowIndex());
            Assert.Equal(-1, entityType.GetProperty("Name").GetShadowIndex());

            Assert.Equal(0, entityType.GetProperty("Id").GetOriginalValueIndex());
            Assert.Equal(-1, entityType.GetProperty("Name").GetOriginalValueIndex());

            Assert.Equal(1, entityType.ShadowPropertyCount());
            Assert.Equal(1, entityType.OriginalValueCount());

            var gameProperty = entityType.GetOrAddProperty("Game", typeof(int), shadowProperty: true);
            gameProperty.IsConcurrencyToken = true;

            var maneProperty = entityType.GetOrAddProperty("Mane", typeof(int), shadowProperty: true);
            maneProperty.IsConcurrencyToken = true;

            Assert.Equal(0, entityType.GetProperty("Game").Index);
            Assert.Equal(1, entityType.GetProperty("Id").Index);
            Assert.Equal(2, entityType.GetProperty("Mane").Index);
            Assert.Equal(3, entityType.GetProperty("Name").Index);

            Assert.Equal(0, entityType.GetProperty("Game").GetShadowIndex());
            Assert.Equal(1, entityType.GetProperty("Id").GetShadowIndex());
            Assert.Equal(2, entityType.GetProperty("Mane").GetShadowIndex());
            Assert.Equal(-1, entityType.GetProperty("Name").GetShadowIndex());

            Assert.Equal(0, entityType.GetProperty("Game").GetOriginalValueIndex());
            Assert.Equal(1, entityType.GetProperty("Id").GetOriginalValueIndex());
            Assert.Equal(2, entityType.GetProperty("Mane").GetOriginalValueIndex());
            Assert.Equal(-1, entityType.GetProperty("Name").GetOriginalValueIndex());

            Assert.Equal(3, entityType.ShadowPropertyCount());
            Assert.Equal(3, entityType.OriginalValueCount());

            gameProperty.IsConcurrencyToken = false;
            nameProperty.IsConcurrencyToken = true;

            Assert.Equal(0, entityType.GetProperty("Game").Index);
            Assert.Equal(1, entityType.GetProperty("Id").Index);
            Assert.Equal(2, entityType.GetProperty("Mane").Index);
            Assert.Equal(3, entityType.GetProperty("Name").Index);

            Assert.Equal(0, entityType.GetProperty("Game").GetShadowIndex());
            Assert.Equal(1, entityType.GetProperty("Id").GetShadowIndex());
            Assert.Equal(2, entityType.GetProperty("Mane").GetShadowIndex());
            Assert.Equal(-1, entityType.GetProperty("Name").GetShadowIndex());

            Assert.Equal(-1, entityType.GetProperty("Game").GetOriginalValueIndex());
            Assert.Equal(0, entityType.GetProperty("Id").GetOriginalValueIndex());
            Assert.Equal(1, entityType.GetProperty("Mane").GetOriginalValueIndex());
            Assert.Equal(2, entityType.GetProperty("Name").GetOriginalValueIndex());

            Assert.Equal(3, entityType.ShadowPropertyCount());
            Assert.Equal(3, entityType.OriginalValueCount());

            gameProperty.IsShadowProperty = false;
            nameProperty.IsShadowProperty = true;

            Assert.Equal(0, entityType.GetProperty("Game").Index);
            Assert.Equal(1, entityType.GetProperty("Id").Index);
            Assert.Equal(2, entityType.GetProperty("Mane").Index);
            Assert.Equal(3, entityType.GetProperty("Name").Index);

            Assert.Equal(-1, entityType.GetProperty("Game").GetShadowIndex());
            Assert.Equal(0, entityType.GetProperty("Id").GetShadowIndex());
            Assert.Equal(1, entityType.GetProperty("Mane").GetShadowIndex());
            Assert.Equal(2, entityType.GetProperty("Name").GetShadowIndex());

            Assert.Equal(-1, entityType.GetProperty("Game").GetOriginalValueIndex());
            Assert.Equal(0, entityType.GetProperty("Id").GetOriginalValueIndex());
            Assert.Equal(1, entityType.GetProperty("Mane").GetOriginalValueIndex());
            Assert.Equal(2, entityType.GetProperty("Name").GetOriginalValueIndex());

            Assert.Equal(3, entityType.ShadowPropertyCount());
            Assert.Equal(3, entityType.OriginalValueCount());
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:85,代码来源:EntityTypeTest.cs

示例10: Only_required_properties_have_original_value_indexes_when_using_lazy_original_values

        public void Only_required_properties_have_original_value_indexes_when_using_lazy_original_values()
        {
            var entityType = new EntityType(typeof(FullNotificationEntity), new Model());

            entityType.GetOrAddProperty("Name", typeof(string)).IsConcurrencyToken = true;
            entityType.GetOrAddProperty("Id", typeof(int));

            Assert.Equal(-1, entityType.GetProperty("Id").GetOriginalValueIndex());
            Assert.Equal(0, entityType.GetProperty("Name").GetOriginalValueIndex());

            Assert.Equal(1, entityType.OriginalValueCount());
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:12,代码来源:EntityTypeTest.cs

示例11: BuildModel

        private static IModel BuildModel()
        {
            var model = new Model();
            var builder = new ModelBuilder(model);

            builder.Annotation("ModelAnnotation1", "ModelValue1");
            builder.Annotation("ModelAnnotation2", "ModelValue2");

            var entityType1 = new EntityType(typeof(KoolEntity1));
            var property = entityType1.AddProperty("Id1", typeof(int));
            entityType1.SetKey(property);
            entityType1.AddProperty("Id2", typeof(Guid));
            entityType1.AddProperty("KoolEntity2Id", typeof(int));
            model.AddEntityType(entityType1);

            var entityType2 = new EntityType(typeof(KoolEntity2));
            entityType2.AddProperty("KoolEntity1Id1", typeof(int));
            entityType2.AddProperty("KoolEntity1Id2", typeof(Guid));
            entityType2.AddProperty("KoolEntity3Id", typeof(int));
            model.AddEntityType(entityType2);

            var entityType3 = new EntityType(typeof(KoolEntity3));
            entityType3.AddProperty("KoolEntity4Id", typeof(int));
            model.AddEntityType(entityType3);

            var entityType4 = new EntityType(typeof(KoolEntity4));
            model.AddEntityType(entityType4);

            var entityType5 = new EntityType(typeof(KoolEntity5));
            model.AddEntityType(entityType5);

            var entityType6 = new EntityType(typeof(KoolEntity6));
            entityType6.AddProperty("Kool5Id", typeof(int));
            model.AddEntityType(entityType6);

            for (var i = 7; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                Assert.NotNull(type);

                model.AddEntityType(new EntityType(type));
            }

            for (var i = 2; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                var entityType = model.GetEntityType(type);
                var id = entityType.AddProperty(entityType.Type.GetProperty("Id"));
                entityType.SetKey(id);
            }

            for (var i = 1; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                var entityType = model.GetEntityType(type);

                entityType.Annotations.Add(new Annotation("Annotation1", "Value1"));
                entityType.Annotations.Add(new Annotation("Annotation2", "Value2"));

                var foo = entityType.AddProperty(entityType.Type.GetProperty("Foo" + i));

                foo.Annotations.Add(new Annotation("Foo" + i + "Annotation1", "Foo" + i + "Value1"));
                foo.Annotations.Add(new Annotation("Foo" + i + "Annotation2", "Foo" + i + "Value2"));

                var goo = entityType.AddProperty(entityType.Type.GetProperty("Goo" + i));
            }

            var fk11 = entityType1.AddForeignKey(entityType2.GetKey(), new[] { entityType1.GetProperty("KoolEntity2Id") });
            var fk21 = entityType2.AddForeignKey(entityType1.GetKey(), new[] { entityType2.GetProperty("KoolEntity1Id1") });
            var fk22 = entityType2.AddForeignKey(entityType3.GetKey(), new[] { entityType2.GetProperty("KoolEntity3Id") });
            var fk31 = entityType3.AddForeignKey(entityType4.GetKey(), new[] { entityType3.GetProperty("KoolEntity4Id") });
            var fk61 = entityType6.AddForeignKey(entityType5.GetKey(), new[] { entityType6.GetProperty("Kool5Id") });

            entityType1.AddNavigation(new Navigation(fk11, "NavTo2", pointsToPrincipal: true));
            entityType1.AddNavigation(new Navigation(fk21, "NavTo2s", pointsToPrincipal: false));
            entityType2.AddNavigation(new Navigation(fk21, "NavTo1", pointsToPrincipal: true));
            entityType2.AddNavigation(new Navigation(fk11, "NavTo1s", pointsToPrincipal: false));
            entityType2.AddNavigation(new Navigation(fk22, "NavTo3", pointsToPrincipal: true));
            entityType3.AddNavigation(new Navigation(fk22, "NavTo2s", pointsToPrincipal: false));
            entityType3.AddNavigation(new Navigation(fk31, "NavTo4", pointsToPrincipal: true));
            entityType4.AddNavigation(new Navigation(fk31, "NavTo3s", pointsToPrincipal: false));
            entityType5.AddNavigation(new Navigation(fk61, "Kool6s", pointsToPrincipal: false));
            entityType6.AddNavigation(new Navigation(fk61, "Kool5", pointsToPrincipal: true));

            return model;
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:89,代码来源:CompiledModelTest.cs

示例12: Can_get_property_and_can_try_get_property

        public void Can_get_property_and_can_try_get_property()
        {
            var entityType = new EntityType(typeof(Customer));
            entityType.AddProperty(Customer.IdProperty);

            Assert.Equal("Id", entityType.TryGetProperty("Id").Name);
            Assert.Equal("Id", entityType.GetProperty("Id").Name);

            Assert.Null(entityType.TryGetProperty("Nose"));

            Assert.Equal(
                Strings.FormatPropertyNotFound("Nose", "Customer"),
                Assert.Throws<ModelItemNotFoundException>(() => entityType.GetProperty("Nose")).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:14,代码来源:EntityTypeTest.cs

示例13: Can_get_property_and_can_try_get_property

        public void Can_get_property_and_can_try_get_property()
        {
            var entityType = new EntityType(typeof(Customer), new Model());
            var property = entityType.GetOrAddProperty(Customer.IdProperty);

            Assert.Same(property, entityType.FindProperty(Customer.IdProperty));
            Assert.Same(property, entityType.FindProperty("Id"));
            Assert.Same(property, entityType.GetProperty(Customer.IdProperty));
            Assert.Same(property, entityType.GetProperty("Id"));

            Assert.Null(entityType.FindProperty("Nose"));

            Assert.Equal(
                Strings.PropertyNotFound("Nose", typeof(Customer).FullName),
                Assert.Throws<ModelItemNotFoundException>(() => entityType.GetProperty("Nose")).Message);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:16,代码来源:EntityTypeTest.cs

示例14: Only_required_properties_have_original_value_indexes_when_using_lazy_original_values

        public void Only_required_properties_have_original_value_indexes_when_using_lazy_original_values()
        {
            var entityType = new EntityType(typeof(FullNotificationEntity));

            entityType.AddProperty("Name", typeof(string), shadowProperty: false, concurrencyToken: true);
            entityType.AddProperty("Id", typeof(int));

            Assert.Equal(-1, entityType.GetProperty("Id").OriginalValueIndex);
            Assert.Equal(0, entityType.GetProperty("Name").OriginalValueIndex);

            Assert.Equal(1, entityType.OriginalValueCount);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:12,代码来源:EntityTypeTest.cs

示例15: All_properties_have_original_value_indexes_when_using_eager_original_values

        public void All_properties_have_original_value_indexes_when_using_eager_original_values()
        {
            var entityType = new EntityType(typeof(FullNotificationEntity)) { UseLazyOriginalValues = false };

            entityType.AddProperty("Name", typeof(string));
            entityType.AddProperty("Id", typeof(int));

            Assert.Equal(0, entityType.GetProperty("Id").OriginalValueIndex);
            Assert.Equal(1, entityType.GetProperty("Name").OriginalValueIndex);

            Assert.Equal(2, entityType.OriginalValueCount);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:12,代码来源:EntityTypeTest.cs


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