2021-12-22 17:04:38 +08:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Sample.SqlServer.DbContexts;
|
|
|
|
|
using ShardingCore;
|
2022-07-01 23:29:37 +08:00
|
|
|
|
using ShardingCore.Core;
|
2022-07-02 00:05:35 +08:00
|
|
|
|
using ShardingCore.Core.RuntimeContexts;
|
2021-12-22 17:04:38 +08:00
|
|
|
|
|
|
|
|
|
namespace Sample.SqlServer
|
|
|
|
|
{
|
|
|
|
|
public class DbContextHelper
|
|
|
|
|
{
|
2022-07-01 23:29:37 +08:00
|
|
|
|
public static DbContext CreateDbContextByString(string connectionString,IShardingRuntimeContext shardingRuntimeContext)
|
2021-12-22 17:04:38 +08:00
|
|
|
|
{
|
|
|
|
|
var dbContextOptionsBuilder = new DbContextOptionsBuilder<DefaultShardingDbContext>();
|
2022-12-09 22:20:16 +08:00
|
|
|
|
dbContextOptionsBuilder.UseSqlServer(connectionString).UseSharding(shardingRuntimeContext);
|
2021-12-22 17:04:38 +08:00
|
|
|
|
return new DefaultShardingDbContext(dbContextOptionsBuilder.Options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|