本文整理汇总了C#中ConcurrencyModel.F1Context.Entry方法的典型用法代码示例。如果您正苦于以下问题:C# F1Context.Entry方法的具体用法?C# F1Context.Entry怎么用?C# F1Context.Entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrencyModel.F1Context
的用法示例。
在下文中一共展示了F1Context.Entry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Non_generic_reference_navigation_property_can_be_loaded_and_IsLoaded_is_set
public void Non_generic_reference_navigation_property_can_be_loaded_and_IsLoaded_is_set()
{
using (var context = new F1Context())
{
context.Configuration.LazyLoadingEnabled = false;
var driver = context.Drivers.Single(d => d.Name == "Jenson Button");
var teamReference = context.Entry((object)driver).Reference("Team");
Assert.False(teamReference.IsLoaded);
teamReference.Load();
Assert.True(teamReference.IsLoaded);
Assert.Equal(Team.McLaren, driver.Team.Id);
}
}
示例2: Generic_collection_navigation_property_can_be_loaded_and_IsLoaded_is_set
public void Generic_collection_navigation_property_can_be_loaded_and_IsLoaded_is_set()
{
using (var context = new F1Context())
{
context.Configuration.LazyLoadingEnabled = false;
var team = context.Teams.Find(Team.McLaren);
var driversCollection = context.Entry(team).Collection(t => t.Drivers);
Assert.False(driversCollection.IsLoaded);
driversCollection.Load();
Assert.True(driversCollection.IsLoaded);
Assert.Equal(3, team.Drivers.Count);
}
}
示例3: Related_collection_reload_after_detach_can_be_avoided_by_setting_IsLoaded_to_true
public void Related_collection_reload_after_detach_can_be_avoided_by_setting_IsLoaded_to_true()
{
using (var context = new F1Context())
{
var team = context.Teams.Find(Team.McLaren);
var driversCollection = context.Entry(team).Collection(t => t.Drivers);
Assert.Equal(3, team.Drivers.Count);
Assert.True(driversCollection.IsLoaded);
context.Entry(team.Drivers.First()).State = EntityState.Detached;
Assert.False(driversCollection.IsLoaded);
driversCollection.IsLoaded = true;
Assert.Equal(2, team.Drivers.Count);
}
}
示例4: TestDetectChanges
private void TestDetectChanges(Action<F1Context> setupContext, Action<F1Context> actOnContext,
bool autoDetectChanges, bool? expectDetectChanges = null)
{
using (var context = new F1Context())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;
setupContext(context);
var mclaren = context.Teams.Find(Team.McLaren);
var larryEntry = context.Entry(new Driver { Name = "Larry David" });
mclaren.Drivers.Add(larryEntry.Entity);
actOnContext(context);
Assert.Equal(expectDetectChanges ?? autoDetectChanges ? EntityState.Added : EntityState.Detached,
larryEntry.State);
}
}
示例5: Query_for_many_to_many_doesnt_work_well
public void Query_for_many_to_many_doesnt_work_well()
{
using (var context = new F1Context())
{
context.Configuration.LazyLoadingEnabled = false;
var team = context.Teams.Find(Team.McLaren);
var sponsorsCollection = context.Entry(team).Collection(t => t.Sponsors);
var query = sponsorsCollection.Query();
query.Load();
Assert.False(sponsorsCollection.IsLoaded);
// This is due to a bug in CreateSourceQuery in core EF that cannot
// be fixed in the productivity improvements.
Assert.Equal(0, team.Sponsors.Count);
}
}
示例6: Non_Generic_Query_for_collection_loads_related_end
public void Non_Generic_Query_for_collection_loads_related_end()
{
using (var context = new F1Context())
{
context.Configuration.LazyLoadingEnabled = false;
var team = context.Teams.Find(Team.McLaren);
var driversCollection = context.Entry(team).Collection("Drivers");
var query = driversCollection.Query();
query.Cast<Driver>().Where(d => d.Wins > 0).Load(); // Should only bring in two drivers
Assert.False(driversCollection.IsLoaded);
Assert.Equal(2, team.Drivers.Count);
query.Load();
Assert.False(driversCollection.IsLoaded);
Assert.Equal(3, team.Drivers.Count);
}
}
示例7: DbPropertyEntry_method_can_be_used_on_previously_detached_entry_after_the_entity_becomes_tracked
private void DbPropertyEntry_method_can_be_used_on_previously_detached_entry_after_the_entity_becomes_tracked(
Action<DbPropertyEntry> test)
{
using (var context = new F1Context())
{
var team = new Team
{ Id = -1, Name = "Wubbsy Racing", Chassis = new Chassis { TeamId = -1, Name = "Wubbsy" } };
var entry = context.Entry(team).Property(t => t.Name);
context.Teams.Attach(team);
test(entry); // Just testing here that this doesn't throw
}
}
示例8: using
public void Setting_current_value_of_reference_nav_prop_to_null_for_an_independent_association_clears_the_relationship_even_if_it_is_not_loaded()
{
using (var context = new F1Context())
{
context.Configuration.LazyLoadingEnabled = false;
var team = context.Teams.Find(Team.McLaren);
Assert.Null(team.Engine);
Assert.Equal(0, ((IObjectContextAdapter)context).ObjectContext
.ObjectStateManager
.GetObjectStateEntries(EntityState.Deleted)
.Where(e => e.IsRelationship)
.Count());
context.Entry(team).Reference(p => p.Engine).CurrentValue = null;
Assert.Null(team.Engine);
Assert.Equal(1, ((IObjectContextAdapter)context).ObjectContext
.ObjectStateManager
.GetObjectStateEntries(EntityState.Deleted)
.Where(e => e.IsRelationship)
.Count());
}
}
示例9: Collection_navigation_property_can_be_reloaded_even_if_marked_as_loaded
public void Collection_navigation_property_can_be_reloaded_even_if_marked_as_loaded()
{
using (var context = new F1Context())
{
context.Configuration.LazyLoadingEnabled = false;
var team = context.Teams.Find(Team.McLaren);
var driversCollection = context.Entry(team).Collection(t => t.Drivers);
// Load drivers for the first time
driversCollection.Load();
Assert.True(driversCollection.IsLoaded);
Assert.Equal(3, team.Drivers.Count);
// Add a new driver to the database
using (var innerContext = new F1Context())
{
innerContext.Drivers.Add(new Driver { Name = "Larry David", TeamId = Team.McLaren });
innerContext.SaveChanges();
}
// Now force load again
Assert.True(driversCollection.IsLoaded);
driversCollection.Load();
Assert.True(driversCollection.IsLoaded);
Assert.Equal(4, team.Drivers.Count);
}
}
示例10: RejectPropertyChanges_is_noop_for_a_property_that_is_not_modified
public void RejectPropertyChanges_is_noop_for_a_property_that_is_not_modified()
{
using (var context = new F1Context())
{
var hamilton = context.Drivers.Where(d => d.Name == "Lewis Hamilton").Single();
context.Entry(hamilton).Property(d => d.Podiums).CurrentValue = 1000;
var stateEntry = GetObjectContext(context).ObjectStateManager.GetObjectStateEntry(hamilton);
stateEntry.RejectPropertyChanges("Name");
Assert.Equal(EntityState.Modified, stateEntry.State);
Assert.Equal(1, stateEntry.GetModifiedProperties().Count());
Assert.True(stateEntry.GetModifiedProperties().Contains("Podiums"));
}
}
示例11: Collection_navigation_property_can_be_reloaded_with_AppendOnly_semantics
public void Collection_navigation_property_can_be_reloaded_with_AppendOnly_semantics()
{
using (var context = new F1Context())
{
context.Configuration.LazyLoadingEnabled = false;
var team = context.Teams.Find(Team.McLaren);
var driversCollection = context.Entry(team).Collection(t => t.Drivers);
// Load drivers for the first time
driversCollection.Load();
Assert.True(driversCollection.IsLoaded);
Assert.Equal(3, team.Drivers.Count);
// Now detach one driver from the collection and modify another one; the collection becomes unloaded
context.Entry(context.Drivers.Local.Single(d => d.Name == "Jenson Button")).State = EntityState.Detached;
context.Drivers.Local.Single(d => d.Name == "Lewis Hamilton").Wins = -1;
// Check the collection has become unloaded because of the detach. Reload it.
Assert.False(driversCollection.IsLoaded);
Assert.Equal(2, team.Drivers.Count);
driversCollection.Load();
// The detached driver should be back and the modified driver should not have been touched
Assert.True(driversCollection.IsLoaded);
Assert.Equal(3, team.Drivers.Count);
Assert.Equal(-1, context.Drivers.Local.Single(d => d.Name == "Lewis Hamilton").Wins);
}
}
示例12: Reference_navigation_property_can_be_reloaded_with_AppendOnly_semantics
public void Reference_navigation_property_can_be_reloaded_with_AppendOnly_semantics()
{
using (var context = new F1Context())
{
context.Configuration.LazyLoadingEnabled = false;
var driver = context.Drivers.Single(d => d.Name == "Jenson Button");
var teamReference = context.Entry(driver).Reference(d => d.Team);
teamReference.Load();
Assert.True(teamReference.IsLoaded);
driver.Team.Principal = "Larry David";
Assert.True(teamReference.IsLoaded);
teamReference.Load();
Assert.Equal("Larry David", driver.Team.Principal);
}
}
示例13: Non_generic_collection_navigation_property_can_be_loaded_asynchronously_and_IsLoaded_is_set
public void Non_generic_collection_navigation_property_can_be_loaded_asynchronously_and_IsLoaded_is_set()
{
using (var context = new F1Context())
{
context.Configuration.LazyLoadingEnabled = false;
var team = context.Teams.Find(Team.McLaren);
var driversCollection = context.Entry((object)team).Collection("Drivers");
Assert.False(driversCollection.IsLoaded);
driversCollection.LoadAsync().Wait();
Assert.True(driversCollection.IsLoaded);
Assert.Equal(3, team.Drivers.Count);
}
}
示例14: Lazy_loading_no_longer_happens_after_setting_reference_to_null_for_FK_relationship
public void Lazy_loading_no_longer_happens_after_setting_reference_to_null_for_FK_relationship()
{
using (var context = new F1Context())
{
var driver = context.Drivers.First();
context.Entry(driver).Reference(p => p.Team).CurrentValue = null;
Assert.Null(driver.Team); // Accessing the reference does not cause it to be loaded
}
}
示例15: IsPropertyChanged_throws_for_a_deleted_entity
public void IsPropertyChanged_throws_for_a_deleted_entity()
{
using (var context = new F1Context())
{
var hamilton = context.Drivers.Where(d => d.Name == "Lewis Hamilton").Single();
var stateEntry = GetObjectContext(context).ObjectStateManager.GetObjectStateEntry(hamilton);
context.Entry(hamilton).State = EntityState.Deleted;
Assert.Throws<InvalidOperationException>(() => stateEntry.IsPropertyChanged("Name")).ValidateMessage(
"ObjectStateEntry_SetModifiedStates");
}
}