-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14276 from abpframework/MyProjectNameDbContextFac…
…tory-6.0 Add `MyProjectNameDbContextFactory` to `nolayers` project.
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...pnet-core/MyCompanyName.MyProjectName.Blazor.Server/Data/MyProjectNameDbContextFactory.cs
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,31 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
|
||
namespace MyCompanyName.MyProjectName.Data; | ||
|
||
public class MyProjectNameDbContextFactory : IDesignTimeDbContextFactory<MyProjectNameDbContext> | ||
{ | ||
public MyProjectNameDbContext CreateDbContext(string[] args) | ||
{ | ||
//<TEMPLATE-REMOVE IF-NOT='dbms:PostgreSQL'> | ||
// https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic | ||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); | ||
//</TEMPLATE-REMOVE> | ||
|
||
var configuration = BuildConfiguration(); | ||
|
||
var builder = new DbContextOptionsBuilder<MyProjectNameDbContext>() | ||
.UseSqlServer(configuration.GetConnectionString("Default")); | ||
|
||
return new MyProjectNameDbContext(builder.Options); | ||
} | ||
|
||
private static IConfigurationRoot BuildConfiguration() | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: false); | ||
|
||
return builder.Build(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...layers/aspnet-core/MyCompanyName.MyProjectName.Host/Data/MyProjectNameDbContextFactory.cs
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,31 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
|
||
namespace MyCompanyName.MyProjectName.Data; | ||
|
||
public class MyProjectNameDbContextFactory : IDesignTimeDbContextFactory<MyProjectNameDbContext> | ||
{ | ||
public MyProjectNameDbContext CreateDbContext(string[] args) | ||
{ | ||
//<TEMPLATE-REMOVE IF-NOT='dbms:PostgreSQL'> | ||
// https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic | ||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); | ||
//</TEMPLATE-REMOVE> | ||
|
||
var configuration = BuildConfiguration(); | ||
|
||
var builder = new DbContextOptionsBuilder<MyProjectNameDbContext>() | ||
.UseSqlServer(configuration.GetConnectionString("Default")); | ||
|
||
return new MyProjectNameDbContext(builder.Options); | ||
} | ||
|
||
private static IConfigurationRoot BuildConfiguration() | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: false); | ||
|
||
return builder.Build(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...olayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/Data/MyProjectNameDbContextFactory.cs
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,31 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
|
||
namespace MyCompanyName.MyProjectName.Data; | ||
|
||
public class MyProjectNameDbContextFactory : IDesignTimeDbContextFactory<MyProjectNameDbContext> | ||
{ | ||
public MyProjectNameDbContext CreateDbContext(string[] args) | ||
{ | ||
//<TEMPLATE-REMOVE IF-NOT='dbms:PostgreSQL'> | ||
// https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic | ||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); | ||
//</TEMPLATE-REMOVE> | ||
|
||
var configuration = BuildConfiguration(); | ||
|
||
var builder = new DbContextOptionsBuilder<MyProjectNameDbContext>() | ||
.UseSqlServer(configuration.GetConnectionString("Default")); | ||
|
||
return new MyProjectNameDbContext(builder.Options); | ||
} | ||
|
||
private static IConfigurationRoot BuildConfiguration() | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: false); | ||
|
||
return builder.Build(); | ||
} | ||
} |