Thorsten Sommer
c41d000bf0
- Added factory class for EF tooling - Removed no longer needed Program.cs
28 lines
1004 B
C#
28 lines
1004 B
C#
using Microsoft.EntityFrameworkCore.Design;
|
|
|
|
namespace DataModel.Database.Common;
|
|
|
|
/// <summary>
|
|
/// This factory is used by the EF tooling e.g. to create migrations.
|
|
/// </summary>
|
|
public sealed class DataContextFactory : IDesignTimeDbContextFactory<DataContext>
|
|
{
|
|
private const string ENV_EF_TOOLING_DATABASE = "ENV_EF_TOOLING_DATABASE";
|
|
|
|
#region Implementation of IDesignTimeDbContextFactory<out DataContext>
|
|
|
|
/// <inheritdoc />
|
|
public DataContext CreateDbContext(string[] args)
|
|
{
|
|
var dataFile = Environment.GetEnvironmentVariable(ENV_EF_TOOLING_DATABASE);
|
|
if (string.IsNullOrWhiteSpace(dataFile))
|
|
{
|
|
Console.WriteLine("In order to use EF tooling, point the environment variable ENV_EF_TOOLING_DATABASE to the data file, which should be used for the EF tooling.");
|
|
Environment.Exit(100);
|
|
}
|
|
|
|
return Setup.CreateDatabaseInstance4Tooling(dataFile, false);
|
|
}
|
|
|
|
#endregion
|
|
} |