本文整理汇总了C#中BronieContext类的典型用法代码示例。如果您正苦于以下问题:C# BronieContext类的具体用法?C# BronieContext怎么用?C# BronieContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BronieContext类属于命名空间,在下文中一共展示了BronieContext类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Can_use_sequential_GUID_end_to_end_async
public async Task Can_use_sequential_GUID_end_to_end_async()
{
var serviceProvider = new ServiceCollection()
.AddEntityFramework()
.AddSqlServer()
.ServiceCollection
.BuildServiceProvider();
using (var context = new BronieContext(serviceProvider, "GooieBronies"))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
for (var i = 0; i < 50; i++)
{
await context.AddAsync(new Pegasus { Name = "Rainbow Dash " + i });
}
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider, "GooieBronies"))
{
// TODO: Currently test passes because SQL Server happens to return values in
// inserted order. When OrderBy is done on server it should be added to the query.
//var pegasuses = await context.Pegasuses.OrderBy(e => e.Id).ToListAsync();
var pegasuses = await context.Pegasuses.ToListAsync();
for (var i = 0; i < 50; i++)
{
Assert.Equal("Rainbow Dash " + i, pegasuses[i].Name);
}
}
}
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:34,代码来源:SequentialGuidEndToEndTest.cs
示例2: Can_use_explicit_values
public async Task Can_use_explicit_values()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkSqlServer()
.BuildServiceProvider();
var guids = new List<Guid>();
using (var context = new BronieContext(serviceProvider, "GooieExplicitBronies"))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
for (var i = 0; i < 50; i++)
{
guids.Add(context.Add(new Pegasus { Name = "Rainbow Dash " + i, Index = i, Id = Guid.NewGuid() }).Entity.Id);
}
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider, "GooieExplicitBronies"))
{
var pegasuses = await context.Pegasuses.OrderBy(e => e.Index).ToListAsync();
for (var i = 0; i < 50; i++)
{
Assert.Equal("Rainbow Dash " + i, pegasuses[i].Name);
Assert.Equal(guids[i], pegasuses[i].Id);
}
}
}
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:32,代码来源:SequentialGuidEndToEndTest.cs
示例3: Can_use_GUIDs_end_to_end_async
public async Task Can_use_GUIDs_end_to_end_async()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();
var guids = new List<Guid>();
var guidsHash = new HashSet<Guid>();
using (var context = new BronieContext(serviceProvider))
{
for (var i = 0; i < 10; i++)
{
guids.Add(context.Add(new Pegasus { Name = "Rainbow Dash " + i }).Entity.Id);
guidsHash.Add(guids.Last());
}
await context.SaveChangesAsync();
}
Assert.Equal(10, guidsHash.Count);
using (var context = new BronieContext(serviceProvider))
{
var pegasuses = await context.Pegasuses.OrderBy(e => e.Name).ToListAsync();
for (var i = 0; i < 10; i++)
{
Assert.Equal(guids[i], pegasuses[i].Id);
}
}
}
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:31,代码来源:GuidValueGeneratorEndToEndTest.cs
示例4: Can_use_sequential_GUID_end_to_end_async
public async Task Can_use_sequential_GUID_end_to_end_async()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkSqlServer()
.BuildServiceProvider();
using (var context = new BronieContext(serviceProvider, "GooieBronies"))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
for (var i = 0; i < 50; i++)
{
context.Add(new Pegasus { Name = "Rainbow Dash " + i });
}
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider, "GooieBronies"))
{
var pegasuses = await context.Pegasuses.OrderBy(e => e.Id).ToListAsync();
for (var i = 0; i < 50; i++)
{
Assert.Equal("Rainbow Dash " + i, pegasuses[i].Name);
}
}
}
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:29,代码来源:SequentialGuidEndToEndTest.cs
示例5: Can_use_sequence_end_to_end_async
public async Task Can_use_sequence_end_to_end_async()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkSqlServer()
.BuildServiceProvider();
using (var context = new BronieContext(serviceProvider, "BroniesAsync"))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
await AddEntitiesAsync(serviceProvider, "BroniesAsync");
await AddEntitiesAsync(serviceProvider, "BroniesAsync");
// Use a different service provider so a different generator is used but with
// the same server sequence.
serviceProvider = new ServiceCollection()
.AddEntityFrameworkSqlServer()
.BuildServiceProvider();
await AddEntitiesAsync(serviceProvider, "BroniesAsync");
using (var context = new BronieContext(serviceProvider, "BroniesAsync"))
{
var pegasuses = await context.Pegasuses.ToListAsync();
for (var i = 0; i < 10; i++)
{
Assert.Equal(3, pegasuses.Count(p => p.Name == "Rainbow Dash " + i));
Assert.Equal(3, pegasuses.Count(p => p.Name == "Fluttershy " + i));
}
}
}
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:34,代码来源:SequenceEndToEndTest.cs
示例6: Can_use_generated_values_in_composite_key_end_to_end
public async Task Can_use_generated_values_in_composite_key_end_to_end()
{
var serviceProvider = new ServiceCollection()
.AddEntityFramework()
.AddSqlServer()
.ServiceCollection()
.BuildServiceProvider();
long id1;
var id2 = DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture);
Guid id3;
using (var context = new BronieContext(serviceProvider, "CompositeUnicorns"))
{
context.Database.EnsureCreated();
var added = context.Add(new Unicorn { Id2 = id2, Name = "Rarity" }).Entity;
Assert.True(added.Id1 < 0);
Assert.NotEqual(Guid.Empty, added.Id3);
await context.SaveChangesAsync();
Assert.True(added.Id1 > 0);
id1 = added.Id1;
id3 = added.Id3;
}
using (var context = new BronieContext(serviceProvider, "CompositeUnicorns"))
{
Assert.Equal(1, context.Unicorns.Count(e => e.Id1 == id1 && e.Id2 == id2 && e.Id3 == id3));
}
using (var context = new BronieContext(serviceProvider, "CompositeUnicorns"))
{
var unicorn = context.Unicorns.Single(e => e.Id1 == id1 && e.Id2 == id2 && e.Id3 == id3);
unicorn.Name = "Bad Hair Day";
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider, "CompositeUnicorns"))
{
var unicorn = context.Unicorns.Single(e => e.Id1 == id1 && e.Id2 == id2 && e.Id3 == id3);
Assert.Equal("Bad Hair Day", unicorn.Name);
context.Unicorns.Remove(unicorn);
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider, "CompositeUnicorns"))
{
Assert.Equal(0, context.Unicorns.Count(e => e.Id1 == id1 && e.Id2 == id2 && e.Id3 == id3));
}
}
开发者ID:491134648,项目名称:EntityFramework,代码行数:59,代码来源:CompositeKeyEndToEndTest.cs
示例7: Only_one_part_of_a_composite_key_needs_to_vary_for_uniqueness
public async Task Only_one_part_of_a_composite_key_needs_to_vary_for_uniqueness()
{
var serviceProvider = new ServiceCollection()
.AddEntityFramework()
.AddSqlite()
.ServiceCollection()
.BuildServiceProvider();
var ids = new int[3];
using (var context = new BronieContext(serviceProvider, "CompositeEarthPonies"))
{
context.Database.EnsureCreated();
var pony1 = context.Add(new EarthPony { Id1 = 1, Id2 = 7, Name = "Apple Jack 1" }).Entity;
var pony2 = context.Add(new EarthPony { Id1 = 2, Id2 = 7, Name = "Apple Jack 2" }).Entity;
var pony3 = context.Add(new EarthPony { Id1 = 3, Id2 = 7, Name = "Apple Jack 3" }).Entity;
await context.SaveChangesAsync();
ids[0] = pony1.Id1;
ids[1] = pony2.Id1;
ids[2] = pony3.Id1;
}
using (var context = new BronieContext(serviceProvider, "CompositeEarthPonies"))
{
var ponies = context.EarthPonies.ToList();
Assert.Equal(ponies.Count, ponies.Count(e => e.Name == "Apple Jack 1") * 3);
Assert.Equal("Apple Jack 1", ponies.Single(e => e.Id1 == ids[0]).Name);
Assert.Equal("Apple Jack 2", ponies.Single(e => e.Id1 == ids[1]).Name);
Assert.Equal("Apple Jack 3", ponies.Single(e => e.Id1 == ids[2]).Name);
ponies.Single(e => e.Id1 == ids[1]).Name = "Pinky Pie 2";
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider, "CompositeEarthPonies"))
{
var ponies = context.EarthPonies.ToArray();
Assert.Equal(ponies.Length, ponies.Count(e => e.Name == "Apple Jack 1") * 3);
Assert.Equal("Apple Jack 1", ponies.Single(e => e.Id1 == ids[0]).Name);
Assert.Equal("Pinky Pie 2", ponies.Single(e => e.Id1 == ids[1]).Name);
Assert.Equal("Apple Jack 3", ponies.Single(e => e.Id1 == ids[2]).Name);
context.EarthPonies.RemoveRange(ponies);
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider, "CompositeEarthPonies"))
{
Assert.Equal(0, context.EarthPonies.Count());
}
}
开发者ID:491134648,项目名称:EntityFramework,代码行数:58,代码来源:CompositeKeyEndToEndTest.cs
示例8: AddEntities
private static void AddEntities(IServiceProvider serviceProvider)
{
using (var context = new BronieContext(serviceProvider, "Bronies"))
{
for (var i = 0; i < 10; i++)
{
context.Add(new Pegasus { Name = "Rainbow Dash " + i });
context.Add(new Pegasus { Name = "Fluttershy " + i });
}
context.SaveChanges();
}
}
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:13,代码来源:SequenceEndToEndTest.cs
示例9: AddEntitiesAsync
private static async Task AddEntitiesAsync(IServiceProvider serviceProvider)
{
using (var context = new BronieContext(serviceProvider))
{
for (var i = 0; i < 50; i++)
{
context.Add(new Pegasus { Name = "Rainbow Dash " + i });
context.Add(new Pegasus { Name = "Fluttershy " + i });
}
await context.SaveChangesAsync();
}
}
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:13,代码来源:IntegerGeneratorEndToEndInMemoryTest.cs
示例10: Can_use_two_non_generated_integers_as_composite_key_end_to_end
public async Task Can_use_two_non_generated_integers_as_composite_key_end_to_end()
{
var serviceProvider = new ServiceCollection()
.AddEntityFramework()
.AddSqlServer()
.ServiceCollection()
.BuildServiceProvider();
var ticks = DateTime.UtcNow.Ticks;
using (var context = new BronieContext(serviceProvider, "CompositePegasuses"))
{
context.Database.EnsureCreated();
context.Add(new Pegasus { Id1 = ticks, Id2 = ticks + 1, Name = "Rainbow Dash" });
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider, "CompositePegasuses"))
{
var pegasus = context.Pegasuses.Single(e => e.Id1 == ticks && e.Id2 == ticks + 1);
pegasus.Name = "Rainbow Crash";
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider, "CompositePegasuses"))
{
var pegasus = context.Pegasuses.Single(e => e.Id1 == ticks && e.Id2 == ticks + 1);
Assert.Equal("Rainbow Crash", pegasus.Name);
context.Pegasuses.Remove(pegasus);
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider, "CompositePegasuses"))
{
Assert.Equal(0, context.Pegasuses.Count(e => e.Id1 == ticks && e.Id2 == ticks + 1));
}
}
开发者ID:491134648,项目名称:EntityFramework,代码行数:43,代码来源:CompositeKeyEndToEndTest.cs
示例11: Can_use_sequence_end_to_end
public void Can_use_sequence_end_to_end()
{
var serviceProvider = new ServiceCollection()
.AddEntityFramework()
.AddSqlServer()
.ServiceCollection
.BuildServiceProvider();
using (var context = new BronieContext(serviceProvider, "Bronies"))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
// TODO: Integrate sequence generation into Migrations
CreateDatabaseSequence(context, context.Database.AsRelational().Connection);
}
AddEntities(serviceProvider);
AddEntities(serviceProvider);
// Use a different service provider so a different generator pool is used but with
// the same server sequence.
serviceProvider = new ServiceCollection()
.AddEntityFramework()
.AddSqlServer()
.ServiceCollection
.BuildServiceProvider();
AddEntities(serviceProvider);
using (var context = new BronieContext(serviceProvider, "Bronies"))
{
var pegasuses = context.Pegasuses.ToList();
for (var i = 0; i < 50; i++)
{
Assert.Equal(3, pegasuses.Count(p => p.Name == "Rainbow Dash " + i));
Assert.Equal(3, pegasuses.Count(p => p.Name == "Fluttershy " + i));
}
}
}
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:41,代码来源:SequenceEndToEndTest.cs
示例12: Can_use_sequence_end_to_end_async
public async Task Can_use_sequence_end_to_end_async()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();
await AddEntitiesAsync(serviceProvider);
await AddEntitiesAsync(serviceProvider);
using (var context = new BronieContext(serviceProvider))
{
var pegasuses = await context.Pegasuses.ToListAsync();
for (var i = 0; i < 50; i++)
{
Assert.True(pegasuses.All(p => p.Id > 0));
Assert.Equal(2, pegasuses.Count(p => p.Name == "Rainbow Dash " + i));
Assert.Equal(2, pegasuses.Count(p => p.Name == "Fluttershy " + i));
}
}
}
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:21,代码来源:IntegerGeneratorEndToEndInMemoryTest.cs
示例13: Can_use_sequence_end_to_end
public void Can_use_sequence_end_to_end()
{
var serviceProvider = new ServiceCollection()
.AddEntityFramework()
.AddInMemoryStore()
.ServiceCollection()
.BuildServiceProvider();
AddEntities(serviceProvider);
AddEntities(serviceProvider);
using (var context = new BronieContext(serviceProvider))
{
var pegasuses = context.Pegasuses.ToList();
for (var i = 0; i < 50; i++)
{
Assert.True(pegasuses.All(p => p.Id > 0));
Assert.Equal(2, pegasuses.Count(p => p.Name == "Rainbow Dash " + i));
Assert.Equal(2, pegasuses.Count(p => p.Name == "Fluttershy " + i));
}
}
}
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:23,代码来源:IntegerGeneratorEndToEndInMemoryTest.cs
示例14: AddEntitiesWithIds
private static void AddEntitiesWithIds(IServiceProvider serviceProvider, int idOffset)
{
using (var context = new BronieContext(serviceProvider, "ExplicitBronies"))
{
for (var i = 1; i < 11; i++)
{
context.Add(new Pegasus { Name = "Rainbow Dash " + i, Identifier = i * 100 + idOffset });
context.Add(new Pegasus { Name = "Fluttershy " + i, Identifier = i * 100 + idOffset + 1 });
}
context.SaveChanges();
}
}
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:13,代码来源:SequenceEndToEndTest.cs
示例15: Only_one_part_of_a_composite_key_needs_to_vary_for_uniquness
public async Task Only_one_part_of_a_composite_key_needs_to_vary_for_uniquness()
{
var serviceProvider = new ServiceCollection()
.AddEntityFramework()
.AddInMemoryStore()
.ServiceCollection
.BuildServiceProvider();
var ids = new int[3];
using (var context = new BronieContext(serviceProvider))
{
var pony1 = await context.AddAsync(new EarthPony { Id2 = 7, Name = "Apple Jack 1" });
var pony2 = await context.AddAsync(new EarthPony { Id2 = 7, Name = "Apple Jack 2" });
var pony3 = await context.AddAsync(new EarthPony { Id2 = 7, Name = "Apple Jack 3" });
await context.SaveChangesAsync();
ids[0] = pony1.Id1;
ids[1] = pony2.Id1;
ids[2] = pony3.Id1;
}
using (var context = new BronieContext(serviceProvider))
{
var ponies = context.EarthPonies.ToList();
Assert.Equal(ponies.Count, ponies.Count(e => e.Name == "Apple Jack 1") * 3);
Assert.Equal("Apple Jack 1", ponies.Single(e => e.Id1 == ids[0]).Name);
Assert.Equal("Apple Jack 2", ponies.Single(e => e.Id1 == ids[1]).Name);
Assert.Equal("Apple Jack 3", ponies.Single(e => e.Id1 == ids[2]).Name);
ponies.Single(e => e.Id1 == ids[1]).Name = "Pinky Pie 2";
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider))
{
var ponies = context.EarthPonies.ToList();
Assert.Equal(ponies.Count, ponies.Count(e => e.Name == "Apple Jack 1") * 3);
Assert.Equal("Apple Jack 1", ponies.Single(e => e.Id1 == ids[0]).Name);
Assert.Equal("Pinky Pie 2", ponies.Single(e => e.Id1 == ids[1]).Name);
Assert.Equal("Apple Jack 3", ponies.Single(e => e.Id1 == ids[2]).Name);
context.EarthPonies.RemoveRange(ponies);
await context.SaveChangesAsync();
}
using (var context = new BronieContext(serviceProvider))
{
Assert.Equal(0, context.EarthPonies.Count());
}
}
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:56,代码来源:CompositeKeyEndToEndTest.cs
示例16: CreateDatabaseSequence
private static void CreateDatabaseSequence(BronieContext context, RelationalConnection storeConnection)
{
var executor = new SqlStatementExecutor();
var operations = new SqlServerSequenceValueGeneratorFactory(executor)
.GetUpMigrationOperations(context.Model.GetEntityType(typeof(Pegasus))
.GetProperty("Identifier"));
var sql = new SqlServerMigrationOperationSqlGenerator(new SqlServerTypeMapper())
.Generate(operations);
// TODO: Should be able to get relational connection without cast
var connection = storeConnection.DbConnection;
executor.ExecuteNonQuery(connection, storeConnection.DbTransaction, sql);
}
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:16,代码来源:SequenceEndToEndTest.cs
示例17: Can_use_sequence_end_to_end_from_multiple_contexts_concurrently_async
// [ConditionalFact] Currently disabled due to GitHub issue #266
public async Task Can_use_sequence_end_to_end_from_multiple_contexts_concurrently_async()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkSqlServer()
.BuildServiceProvider();
using (var context = new BronieContext(serviceProvider, "ManyBronies"))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
const int threadCount = 50;
var tests = new Func<Task>[threadCount];
for (var i = 0; i < threadCount; i++)
{
var closureProvider = serviceProvider;
tests[i] = () => AddEntitiesAsync(closureProvider, "ManyBronies");
}
var tasks = tests.Select(Task.Run).ToArray();
foreach (var t in tasks)
{
await t;
}
using (var context = new BronieContext(serviceProvider, "ManyBronies"))
{
var pegasuses = await context.Pegasuses.ToListAsync();
for (var i = 0; i < 50; i++)
{
Assert.Equal(threadCount, pegasuses.Count(p => p.Name == "Rainbow Dash " + i));
Assert.Equal(threadCount, pegasuses.Count(p => p.Name == "Fluttershy " + i));
}
}
}
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:40,代码来源:SequenceEndToEndTest.cs
示例18: Can_use_explicit_values
public void Can_use_explicit_values()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkSqlServer()
.BuildServiceProvider();
using (var context = new BronieContext(serviceProvider, "ExplicitBronies"))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
AddEntitiesWithIds(serviceProvider, 0);
AddEntitiesWithIds(serviceProvider, 2);
// Use a different service provider so a different generator is used but with
// the same server sequence.
serviceProvider = new ServiceCollection()
.AddEntityFrameworkSqlServer()
.BuildServiceProvider();
AddEntitiesWithIds(serviceProvider, 4);
using (var context = new BronieContext(serviceProvider, "ExplicitBronies"))
{
var pegasuses = context.Pegasuses.ToList();
for (var i = 1; i < 11; i++)
{
Assert.Equal(3, pegasuses.Count(p => p.Name == "Rainbow Dash " + i));
Assert.Equal(3, pegasuses.Count(p => p.Name == "Fluttershy " + i));
for (var j = 0; j < 6; j++)
{
pegasuses.Single(p => p.Identifier == i * 100 + j);
}
}
}
}
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:39,代码来源:SequenceEndToEndTest.cs
注:本文中的BronieContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论