Add: NativeAOT support with EF Core. However failed for compiled binary throw Exception in queries. Wait for a stable support for NativeAOT. Add: document for intergration EF Core with NativeAOT.
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using OptixServe.Infrastructure.Configuration;
|
|
using OptixServe.Infrastructure.Data.CompiledModels;
|
|
|
|
namespace OptixServe.Infrastructure.Utilites;
|
|
|
|
public static class DatabaseHelper
|
|
{
|
|
public static string BuildConnectionString(DatabaseSettings dbSettings)
|
|
{
|
|
return dbSettings.Type switch
|
|
{
|
|
DatabaseType.Sqlite => $"Data Source={dbSettings.Host ?? "optixserve.db"}",
|
|
DatabaseType.MySQL => throw new NotSupportedException("MySQL connection is not yet implemented"),
|
|
_ => throw new NotSupportedException($"Database type {dbSettings.Type} is not supported")
|
|
};
|
|
}
|
|
|
|
public static void ConfigureDbContext(DbContextOptionsBuilder options, DatabaseSettings dbSettings)
|
|
{
|
|
if (dbSettings?.Type == DatabaseType.Sqlite)
|
|
{
|
|
var dbPath = dbSettings.Host ?? "optixserve.db";
|
|
var connectionString = $"Data Source={dbPath}";
|
|
|
|
options.UseSqlite(connectionString, b => b.MigrationsAssembly("OptixServe.Infrastructure"))
|
|
.UseModel(AppDbContextModel.Instance);
|
|
|
|
}
|
|
else
|
|
{
|
|
throw new NotImplementedException("Only SQLite database is currently supported");
|
|
}
|
|
}
|
|
}
|