コード例 #1
0
        public virtual void Access_mode_can_be_overriden_at_entity_and_property_levels()
        {
            var model = new Model();

            var entityType1 = model.AddEntityType(typeof(FullProp));
            var e1p1        = entityType1.AddProperty("Id", typeof(int));
            var e1p2        = entityType1.AddProperty("Foo", typeof(int));

            var entityType2 = model.AddEntityType(typeof(ReadOnlyProp));
            var e2p1        = entityType2.AddProperty("Id", typeof(int));
            var e2p2        = entityType2.AddProperty("Foo", typeof(int));

            model.SetPropertyAccessMode(PropertyAccessMode.Field);
            entityType2.SetPropertyAccessMode(PropertyAccessMode.FieldDuringConstruction);
            e2p2.SetPropertyAccessMode(PropertyAccessMode.Property);

            Assert.Equal(PropertyAccessMode.Field, model.GetPropertyAccessMode());

            Assert.Equal(PropertyAccessMode.Field, entityType1.GetPropertyAccessMode());
            Assert.Equal(PropertyAccessMode.Field, e1p1.GetPropertyAccessMode());
            Assert.Equal(PropertyAccessMode.Field, e1p2.GetPropertyAccessMode());

            Assert.Equal(PropertyAccessMode.FieldDuringConstruction, entityType2.GetPropertyAccessMode());
            Assert.Equal(PropertyAccessMode.FieldDuringConstruction, e2p1.GetPropertyAccessMode());
            Assert.Equal(PropertyAccessMode.Property, e2p2.GetPropertyAccessMode());
        }