sharding/samples/Sample.SqlServer/DbContextHelper.cs

19 lines
671 B
C#
Raw Permalink Normal View History

using Microsoft.EntityFrameworkCore;
using Sample.SqlServer.DbContexts;
using ShardingCore;
2022-07-01 23:29:37 +08:00
using ShardingCore.Core;
using ShardingCore.Core.RuntimeContexts;
namespace Sample.SqlServer
{
public class DbContextHelper
{
2022-07-01 23:29:37 +08:00
public static DbContext CreateDbContextByString(string connectionString,IShardingRuntimeContext shardingRuntimeContext)
{
var dbContextOptionsBuilder = new DbContextOptionsBuilder<DefaultShardingDbContext>();
dbContextOptionsBuilder.UseSqlServer(connectionString).UseSharding(shardingRuntimeContext);
return new DefaultShardingDbContext(dbContextOptionsBuilder.Options);
}
}
}