using Microsoft.EntityFrameworkCore.Design;
namespace DataModel.Database.Common;
///
/// This factory is used by the EF tooling e.g. to create migrations.
///
public sealed class DataContextFactory : IDesignTimeDbContextFactory
{
private const string ENV_EF_TOOLING_DATABASE = "ENV_EF_TOOLING_DATABASE";
#region Implementation of IDesignTimeDbContextFactory
///
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
}