コード例 #1
0
        public void Property_values_can_be_read_and_set_using_compiled_metadata_without_reflection()
        {
            var configuration = new DbContextOptions()
                                .UseModel(new _OneTwoThreeContextModel())
                                .BuildConfiguration();

            using (var context = new DbContext(configuration))
            {
                var entity   = new KoolEntity15();
                var property = (_KoolEntity15IdProperty)context.Model.GetEntityType(entity.GetType()).TryGetProperty("Id");

                var stateEntry = context.ChangeTracker.Entry(entity).StateEntry;

                Assert.False(property.GetterCalled);
                Assert.False(property.SetterCalled);

                Assert.Equal(0, stateEntry[property]);
                Assert.True(property.GetterCalled);

                stateEntry[property] = 777;

                Assert.True(property.SetterCalled);
                Assert.Equal(777, stateEntry[property]);
            }
        }
コード例 #2
0
        public void Property_values_can_be_read_and_set_using_compiled_metadata_without_reflection()
        {
            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseModel(new _OneTwoThreeContextModel()).UseInMemoryStore();

            using (var context = new DbContext(optionsBuilder.Options))
            {
                var entity   = new KoolEntity15();
                var property = (_KoolEntity15IdProperty)context.Model.GetEntityType(entity.GetType()).FindProperty("Id");

                var entry = ((IAccessor <InternalEntityEntry>)context.Entry(entity)).Service;

                Assert.False(property.GetterCalled);
                Assert.False(property.SetterCalled);

                Assert.Equal(0, entry[property]);
                Assert.True(property.GetterCalled);

//                entry[property] = 777;
//
//                Assert.True(property.SetterCalled);
//                Assert.Equal(777, entry[property]);
            }
        }
コード例 #3
0
        public void Property_values_can_be_read_and_set_using_compiled_metadata_without_reflection()
        {
            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseModel(new _OneTwoThreeContextModel()).UseInMemoryStore();

            using (var context = new DbContext(optionsBuilder.Options))
            {
                var entity = new KoolEntity15();
                var property = (_KoolEntity15IdProperty)context.Model.GetEntityType(entity.GetType()).FindProperty("Id");

                var entry = ((IAccessor<InternalEntityEntry>)context.Entry(entity)).Service;

                Assert.False(property.GetterCalled);
                Assert.False(property.SetterCalled);

                Assert.Equal(0, entry[property]);
                Assert.True(property.GetterCalled);

//                entry[property] = 777;
//
//                Assert.True(property.SetterCalled);
//                Assert.Equal(777, entry[property]);
            }
        }
コード例 #4
0
        public void Property_values_can_be_read_and_set_using_compiled_metadata_without_reflection()
        {
            var options = new DbContextOptions().UseModel(new _OneTwoThreeContextModel());

            using (var context = new DbContext(options))
            {
                var entity = new KoolEntity15();
                var property = (_KoolEntity15IdProperty)context.Model.GetEntityType(entity.GetType()).TryGetProperty("Id");

                var stateEntry = context.ChangeTracker.Entry(entity).StateEntry;

                Assert.False(property.GetterCalled);
                Assert.False(property.SetterCalled);

                Assert.Equal(0, stateEntry[property]);
                Assert.True(property.GetterCalled);

                stateEntry[property] = 777;

                Assert.True(property.SetterCalled);
                Assert.Equal(777, stateEntry[property]);
            }
        }