本文整理汇总了C#中ConcurrencyModel.F1Context.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# F1Context.SaveChanges方法的具体用法?C# F1Context.SaveChanges怎么用?C# F1Context.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrencyModel.F1Context
的用法示例。
在下文中一共展示了F1Context.SaveChanges方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDetectChangesWithSaveChanges
private void TestDetectChangesWithSaveChanges(bool autoDetectChanges)
{
using (var context = new F1Context())
{
context.Database.Initialize(force: false);
using (new TransactionScope())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;
var mclaren = context.Teams.Find(Team.McLaren);
var larryEntry = context.Entry(new Driver { Name = "Larry David" });
mclaren.Drivers.Add(larryEntry.Entity);
Assert.Equal(autoDetectChanges ? EntityState.Added : EntityState.Detached, larryEntry.State);
context.SaveChanges();
Assert.Equal(autoDetectChanges ? EntityState.Unchanged : EntityState.Detached, larryEntry.State);
}
}
}
示例2: 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);
}
}