Ejemplo n.º 1
0
 /// <summary>
 ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
 ///     directly from your code. This API may change or be removed in future releases.
 /// </summary>
 public virtual void EnsureRelationshipSnapshot()
 {
     if (_relationshipsSnapshot.IsEmpty)
     {
         _relationshipsSnapshot = new RelationshipsSnapshot(this);
     }
 }
Ejemplo n.º 2
0
        public void Creates_a_new_key_from_current_value_when_value_not_yet_set_in_sidecar()
        {
            var model = BuildModel();
            var type  = model.GetEntityType(typeof(Banana));

            var entity = new Banana {
                P1 = 7, P2 = 77
            };
            var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity);

            var sidecar = new RelationshipsSnapshot(entry);

            var key = (SimpleEntityKey <int>) new SimpleNullableEntityKeyFactory <int, int?>().Create(
                type, new[] { type.GetProperty("P2") }, sidecar);

            Assert.Equal(77, key.Value);
        }
Ejemplo n.º 3
0
        public void Creates_a_new_key_from_current_value_when_value_not_yet_set_in_sidecar()
        {
            var model        = BuildModel();
            var type         = model.GetEntityType(typeof(Banana));
            var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService <IStateManager>();

            var entity = new Banana {
                P1 = 7, P2 = 77
            };
            var entry = stateManager.GetOrCreateEntry(entity);

            var sidecar = new RelationshipsSnapshot(entry);

            var key = (SimpleEntityKey <int>) new SimpleEntityKeyFactory <int>(type.GetPrimaryKey(), 0)
                      .Create(new[] { type.GetProperty("P2") }, sidecar);

            Assert.Equal(77, key.Value);
        }
        public void Creates_a_new_key_from_a_sidecar_value()
        {
            var model = BuildModel();
            var type  = model.GetEntityType(typeof(Banana));

            var entity = new Banana {
                P1 = 7, P2 = 8
            };
            var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity);

            var sidecar = new RelationshipsSnapshot(entry);

            sidecar[type.GetProperty("P2")] = "Eaten";

            var key = (SimpleEntityKey <string>) new SimpleEntityKeyFactory <string>().Create(
                type, new[] { type.GetProperty("P2") }, sidecar);

            Assert.Equal("Eaten", key.Value);
        }
        public void Creates_a_new_key_from_a_sidecar_value()
        {
            var model        = BuildModel();
            var type         = model.GetEntityType(typeof(Banana));
            var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService <IStateManager>();

            var entity = new Banana {
                P1 = 7, P2 = 8
            };
            var entry = stateManager.GetOrCreateEntry(entity);

            var sidecar = new RelationshipsSnapshot(entry);

            sidecar[type.GetProperty("P2")] = "Eaten";

            var key = (SimpleEntityKey <string>) new SimpleEntityKeyFactory <string>(type.GetPrimaryKey(), null)
                      .Create(new[] { type.GetProperty("P2") }, sidecar);

            Assert.Equal("Eaten", key.Value);
        }
        public void Creates_a_new_key_from_a_sidecar_value()
        {
            var model        = BuildModel();
            var type         = model.GetEntityType(typeof(Banana));
            var stateManager = TestHelpers.CreateContextServices(model).GetRequiredService <StateManager>();

            var entity = new Banana {
                P1 = 7, P2 = 77
            };
            var entry = stateManager.GetOrCreateEntry(entity);

            var sidecar = new RelationshipsSnapshot(entry);

            sidecar[type.GetProperty("P2")] = 78;

            var key = (SimpleEntityKey <int>) new SimpleNullableEntityKeyFactory <int, int?>().Create(
                type, new[] { type.GetProperty("P2") }, sidecar);

            Assert.Equal(78, key.Value);
        }
Ejemplo n.º 7
0
        public void Creates_a_new_key_for_values_from_a_sidecar()
        {
            var model = BuildModel();
            var type  = model.GetEntityType(typeof(Banana));

            var random = new Random();
            var entity = new Banana {
                P4 = 7, P5 = "Ate", P6 = random
            };

            var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity);

            var sidecar = new RelationshipsSnapshot(entry);

            sidecar[type.GetProperty("P4")] = 77;

            var key = (CompositeEntityKey) new CompositeEntityKeyFactory().Create(
                type, new[] { type.GetProperty("P6"), type.GetProperty("P4"), type.GetProperty("P5") }, sidecar);

            Assert.Equal(new object[] { random, 77, "Ate" }, key.Value);
        }
Ejemplo n.º 8
0
        public void Creates_a_new_key_for_values_from_a_sidecar()
        {
            var model        = BuildModel();
            var type         = model.GetEntityType(typeof(Banana));
            var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService <IStateManager>();

            var random = new Random();
            var entity = new Banana {
                P4 = 7, P5 = "Ate", P6 = random
            };

            var entry = stateManager.GetOrCreateEntry(entity);

            var sidecar = new RelationshipsSnapshot(entry);

            sidecar[type.GetProperty("P4")] = 77;

            var key = (CompositeEntityKey) new CompositeEntityKeyFactory(
                type.GetPrimaryKey())
                      .Create(new[] { type.GetProperty("P6"), type.GetProperty("P4"), type.GetProperty("P5") }, sidecar);

            Assert.Equal(new object[] { random, 77, "Ate" }, key.Value);
        }