本文整理汇总了C#中AdvancedPatternsModel.AdvancedPatternsMasterContext.Entry方法的典型用法代码示例。如果您正苦于以下问题:C# AdvancedPatternsMasterContext.Entry方法的具体用法?C# AdvancedPatternsMasterContext.Entry怎么用?C# AdvancedPatternsMasterContext.Entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdvancedPatternsModel.AdvancedPatternsMasterContext
的用法示例。
在下文中一共展示了AdvancedPatternsMasterContext.Entry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DbPropertyValues_ToObject_for_an_entity_works_under_partial_trust
public void DbPropertyValues_ToObject_for_an_entity_works_under_partial_trust()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var buildingClone = (Building)context.Entry(building).CurrentValues.ToObject();
Assert.Equal("Building One", buildingClone.Name);
}
}
示例2: DbPropertyValues_ToObject_for_a_complex_type_works_under_partial_trust
public void DbPropertyValues_ToObject_for_a_complex_type_works_under_partial_trust()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var addressClone =
(Address)context.Entry(building).CurrentValues.GetValue<DbPropertyValues>("Address").ToObject();
Assert.Equal("Redmond", addressClone.City);
}
}
示例3: DbPropertyEntryTest
private void DbPropertyEntryTest(EntityState state, Action<DbEntityEntry<Building>> test)
{
using (var context = new AdvancedPatternsMasterContext())
{
var entry = context.Entry(new Building
{
Name = "Building 18",
Address = new Address
{
Street = "1 Microsoft Way",
City = "Redmond",
State = "WA",
ZipCode = "98052",
County = "KING",
SiteInfo = new SiteInfo { Zone = 2, Environment = "Clean" }
},
NotInModel = "NotInModel",
});
entry.State = state;
test(entry);
}
}
示例4: IsPropertyChanged_returns_true_for_scalar_property_that_is_changed_and_marked_as_modified
public void IsPropertyChanged_returns_true_for_scalar_property_that_is_changed_and_marked_as_modified()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
var stateEntry = GetObjectContext(context).ObjectStateManager.GetObjectStateEntry(building);
entry.Property(b => b.Name).CurrentValue = "Oops I Did It Again!";
Assert.True(entry.Property(b => b.Name).IsModified);
Assert.True(stateEntry.IsPropertyChanged("Name"));
building.Name = "Building Two";
context.ChangeTracker.DetectChanges();
building.Name = "Building One";
context.ChangeTracker.DetectChanges();
Assert.True(entry.Property(b => b.Name).IsModified);
Assert.False(stateEntry.IsPropertyChanged("Name"));
}
}
示例5: IsPropertyChangedTest
private void IsPropertyChangedTest(Action<Building, DbEntityEntry<Building>, ObjectStateEntry> test)
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
var stateEntry = GetObjectContext(context).ObjectStateManager.GetObjectStateEntry(building);
test(building, entry, stateEntry);
}
}
示例6: using
public void Setting_a_nested_complex_property_current_value_onto_a_complex_property_that_is_null_for_a_Detached_entity_throws()
{
using (var context = new AdvancedPatternsMasterContext())
{
var entry = context.Entry(CreateBuilding(nullAddress: true));
Assert.Throws<InvalidOperationException>(
() =>
entry.ComplexProperty(b => b.Address).Property(a => a.SiteInfo).CurrentValue = CreateSiteInfo()).
ValidateMessage(
"DbPropertyValues_CannotSetPropertyOnNullCurrentValue", typeof(SiteInfo).Name,
typeof(Address).Name);
}
}
示例7: ValidateBuildingAndNameNotModified
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"));
}
示例8: ValidateModifiedProperties
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"));
}
示例9: TestPropertyValuePositiveForState
private void TestPropertyValuePositiveForState(Func<DbPropertyEntry<Building, string>, string> getValue,
Action<DbPropertyEntry<Building, string>, string> setValue,
EntityState state)
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
var propEntry = entry.Property(b => b.Name);
entry.State = state;
Assert.Equal("Building One", getValue(propEntry));
setValue(propEntry, "New Building");
Assert.Equal("New Building", getValue(propEntry));
}
}
示例10: using
public void Rejecting_changes_to_a_complex_property_creates_a_new_complex_object_which_is_then_not_detected_as_changed_by_future_DetectChanges()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
var originalAddress = building.Address;
var originalSiteInfo = originalAddress.SiteInfo;
var newAddress = CreateNewAddress();
var newSiteInfo = newAddress.SiteInfo;
entry.ComplexProperty(b => b.Address).CurrentValue = newAddress;
Assert.True(entry.Property(b => b.Address).IsModified);
entry.ComplexProperty(b => b.Address).IsModified = false;
ValidateBuildingAndNameNotModified(context, building);
Assert.NotSame(newAddress, building.Address);
Assert.NotSame(newSiteInfo, building.Address.SiteInfo);
Assert.NotSame(originalAddress, building.Address);
Assert.NotSame(originalSiteInfo, building.Address.SiteInfo);
Assert.Equal("300 Main St", newAddress.Street);
Assert.Equal("Ames", newAddress.City);
Assert.Equal("IA", newAddress.State);
Assert.Equal("50010", newAddress.ZipCode);
Assert.Equal("Contaminated", newAddress.SiteInfo.Environment);
Assert.Equal(3, newAddress.SiteInfo.Zone);
context.ChangeTracker.DetectChanges();
ValidateBuildingAndNameNotModified(context, building);
}
}
示例11: using
Setting_IsModified_to_false_for_a_nested_property_of_a_modified_complex_property_rejects_changes_to_the_top_level_complex_property
()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
entry.ComplexProperty(b => b.Address).Property(a => a.City).CurrentValue = "Madrid";
Assert.True(entry.Property(b => b.Address).IsModified);
entry.ComplexProperty(b => b.Address).Property(a => a.City).IsModified = false;
ValidateBuildingAndNameNotModified(context, building);
}
}
示例12: DbPropertyValues_SetValues_for_an_entity_wih_complex_objects_works_under_partial_trust
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);
}
}
示例13: GetBuildingEntry
private DbEntityEntry<Building> GetBuildingEntry(AdvancedPatternsMasterContext context)
{
var building = new Building();
context.Buildings.Attach(building);
return context.Entry(building);
}
示例14: Original_value_cannot_be_read_or_set_for_an_object_in_the_Added_state
public void Original_value_cannot_be_read_or_set_for_an_object_in_the_Added_state()
{
EntityState state = EntityState.Added;
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
var propEntry = entry.Property(b => b.Name);
entry.State = state;
Assert.Throws<InvalidOperationException>(() => { var _ = propEntry.OriginalValue; }).ValidateMessage(
"DbPropertyValues_CannotGetValuesForState", "OriginalValues", state.ToString());
Assert.Throws<InvalidOperationException>(() => propEntry.OriginalValue = "").ValidateMessage(
"DbPropertyValues_CannotGetValuesForState", "OriginalValues", state.ToString());
}
}
示例15: IsModified_can_be_set_to_true_when_it_is_currently_true
public void IsModified_can_be_set_to_true_when_it_is_currently_true()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
entry.Property(b => b.Name).IsModified = true;
entry.ComplexProperty(b => b.Address).IsModified = true;
entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Zone).IsModified
= true;
entry.Property(b => b.Name).IsModified = true;
entry.ComplexProperty(b => b.Address).IsModified = true;
entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Zone).IsModified
= true;
ValidateModifiedProperties(context, building);
}
}