-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb6037c
commit 3e84506
Showing
20 changed files
with
115 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using EFCore.Sharding; | ||
|
||
namespace DbMigrator | ||
{ | ||
public class CustomContext : GenericDbContext | ||
{ | ||
public CustomContext(GenericDbContext dbContext) | ||
: base(dbContext) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using EFCore.Sharding; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace DbMigrator | ||
{ | ||
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<DbContext> | ||
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<CustomContext>, IDesignTimeServices | ||
{ | ||
public void ConfigureDesignTimeServices(IServiceCollection serviceCollection) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
/// <summary> | ||
/// 创建数据库上下文 | ||
/// </summary> | ||
/// <param name="args"></param> | ||
/// <returns></returns> | ||
public DbContext CreateDbContext(string[] args) | ||
public CustomContext CreateDbContext(string[] args) | ||
{ | ||
return new DbContext1(); | ||
using var host = Host.CreateDefaultBuilder() | ||
.ConfigureServices(services => | ||
{ | ||
services.AddEFCoreSharding(x => | ||
{ | ||
x.MigrationsWithoutForeignKey(); | ||
}); | ||
}).Build(); | ||
host.Start(); | ||
|
||
var db = host.Services | ||
.GetService<IDbFactory>() | ||
.GetDbContext(new DbContextParamters | ||
{ | ||
ConnectionString = "Data Source=localhost;Initial Catalog=DbMigrator;Integrated Security=True", | ||
DbType = DatabaseType.SqlServer, | ||
}); | ||
|
||
return new CustomContext(db); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 0 additions & 68 deletions
68
examples/Demo.DbMigrator/Migrations/20200924134643_InitialCreate.Designer.cs
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
examples/Demo.DbMigrator/Migrations/20200924134643_InitialCreate.cs
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
examples/Demo.DbMigrator/Migrations/DbContext1ModelSnapshot.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace EFCore.Sharding.Config | ||
{ | ||
internal static class Cache | ||
{ | ||
public static IServiceProvider ServiceProvider { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.