private void ValidateBuildingAndNameNotModified(AdvancedPatternsMasterContext context, Building building)
        {
            var entry = context.Entry(building);

            Assert.False(entry.Property(b => b.Name).IsModified);
            Assert.False(entry.ComplexProperty(b => b.Address).IsModified);
            Assert.False(entry.ComplexProperty(b => b.Address).Property(a => a.Street).IsModified);
            Assert.False(entry.ComplexProperty(b => b.Address).Property(a => a.City).IsModified);
            Assert.False(entry.ComplexProperty(b => b.Address).Property(a => a.State).IsModified);
            Assert.False(entry.ComplexProperty(b => b.Address).Property(a => a.ZipCode).IsModified);
            Assert.False(entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).IsModified);
            Assert.False(
                entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Environment).
                    IsModified);
            Assert.False(
                entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Zone).IsModified);

            Assert.Equal("Building One", entry.Property(b => b.Name).CurrentValue);
            Assert.Equal("100 Work St", entry.ComplexProperty(b => b.Address).Property(a => a.Street).CurrentValue);
            Assert.Equal("Redmond", entry.ComplexProperty(b => b.Address).Property(a => a.City).CurrentValue);
            Assert.Equal("WA", entry.ComplexProperty(b => b.Address).Property(a => a.State).CurrentValue);
            Assert.Equal("98052", entry.ComplexProperty(b => b.Address).Property(a => a.ZipCode).CurrentValue);
            Assert.Equal("Clean",
                         entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(
                             i => i.Environment).CurrentValue);
            Assert.Equal(1,
                         entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Zone).
                             CurrentValue);

            var objectContext = GetObjectContext(context);
            var modified = objectContext.ObjectStateManager.GetObjectStateEntry(building).GetModifiedProperties();
            Assert.False(modified.Contains("Name"));
            Assert.False(modified.Contains("Address"));
        }
 private DbEntityEntry<Building> GetBuildingEntry(AdvancedPatternsMasterContext context)
 {
     var building = new Building();
     context.Buildings.Attach(building);
     return context.Entry(building);
 }
        private void ValidateModifiedProperties(AdvancedPatternsMasterContext context, Building building)
        {
            var entry = context.Entry(building);

            Assert.Equal(EntityState.Modified, entry.State);
            Assert.True(entry.Property(b => b.Name).IsModified);
            Assert.True(entry.ComplexProperty(b => b.Address).IsModified);
            Assert.False(entry.Property(b => b.Value).IsModified);
            Assert.True(entry.ComplexProperty(b => b.Address).Property(a => a.Street).IsModified);
            Assert.True(entry.ComplexProperty(b => b.Address).Property(a => a.City).IsModified);
            Assert.True(entry.ComplexProperty(b => b.Address).Property(a => a.State).IsModified);
            Assert.True(entry.ComplexProperty(b => b.Address).Property(a => a.ZipCode).IsModified);
            Assert.True(entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).IsModified);
            Assert.True(
                entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Environment).
                    IsModified);
            Assert.True(
                entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Zone).IsModified);

            var objectContext = GetObjectContext(context);
            var modified = objectContext.ObjectStateManager.GetObjectStateEntry(building).GetModifiedProperties();
            Assert.Equal(2, modified.Count());
            Assert.True(modified.Contains("Name"));
            Assert.True(modified.Contains("Address"));
        }
        public void DbPropertyValues_SetValues_for_an_entity_wih_complex_objects_works_under_partial_trust()
        {
            using (var context = new AdvancedPatternsMasterContext())
            {
                var building = context.Buildings.Single(b => b.Name == "Building One");

                var newBuilding = new Building
                                      {
                                          BuildingId = new Guid(building.BuildingId.ToString()),
                                          Name = "Bag End",
                                          Value = building.Value,
                                          Address = new Address
                                                        {
                                                            Street = "The Hill",
                                                            City = "Hobbiton",
                                                            State = "WF",
                                                            ZipCode = "00001",
                                                            SiteInfo = new SiteInfo
                                                                           {
                                                                               Zone = 3,
                                                                               Environment = "Comfortable"
                                                                           }
                                                        },
                                      };

                context.Entry(building).CurrentValues.SetValues(newBuilding);

                Assert.Equal("Bag End", building.Name);
                Assert.Equal("Hobbiton", building.Address.City);
                Assert.Equal("Comfortable", building.Address.SiteInfo.Environment);
            }
        }