1 Commits

Author SHA1 Message Date
eb021576a5 [Failed] Try to implement NativeAOT support.
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.
2025-07-11 16:07:14 +08:00
9 changed files with 498 additions and 2 deletions

View File

@ -16,7 +16,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization> <InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>false</PublishAot> <PublishAot>true</PublishAot>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -0,0 +1,9 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore.Infrastructure;
using OptixServe.Infrastructure.Data;
using OptixServe.Infrastructure.Data.CompiledModels;
#pragma warning disable 219, 612, 618
#nullable disable
[assembly: DbContextModel(typeof(AppDbContext), typeof(AppDbContextModel))]

View File

@ -0,0 +1,47 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
#pragma warning disable 219, 612, 618
#nullable disable
namespace OptixServe.Infrastructure.Data.CompiledModels
{
[DbContext(typeof(AppDbContext))]
public partial class AppDbContextModel : RuntimeModel
{
private static readonly bool _useOldBehavior31751 =
System.AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue31751", out var enabled31751) && enabled31751;
static AppDbContextModel()
{
var model = new AppDbContextModel();
if (_useOldBehavior31751)
{
model.Initialize();
}
else
{
var thread = new System.Threading.Thread(RunInitialization, 10 * 1024 * 1024);
thread.Start();
thread.Join();
void RunInitialization()
{
model.Initialize();
}
}
model.Customize();
_instance = (AppDbContextModel)model.FinalizeModel();
}
private static AppDbContextModel _instance;
public static IModel Instance => _instance;
partial void Initialize();
partial void Customize();
}
}

View File

@ -0,0 +1,99 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Update.Internal;
#pragma warning disable 219, 612, 618
#nullable disable
namespace OptixServe.Infrastructure.Data.CompiledModels
{
public partial class AppDbContextModel
{
private AppDbContextModel()
: base(skipDetectChanges: false, modelId: new Guid("3214a553-d69f-4844-a587-080f6d463671"), entityTypeCount: 1)
{
}
partial void Initialize()
{
var user = UserEntityType.Create(this);
UserEntityType.CreateAnnotations(user);
AddAnnotation("ProductVersion", "9.0.6");
AddRuntimeAnnotation("Relational:RelationalModelFactory", () => CreateRelationalModel());
}
private IRelationalModel CreateRelationalModel()
{
var relationalModel = new RelationalModel(this);
var user = FindEntityType("OptixServe.Core.Models.User")!;
var defaultTableMappings = new List<TableMappingBase<ColumnMappingBase>>();
user.SetRuntimeAnnotation("Relational:DefaultMappings", defaultTableMappings);
var optixServeCoreModelsUserTableBase = new TableBase("OptixServe.Core.Models.User", null, relationalModel);
var idColumnBase = new ColumnBase<ColumnMappingBase>("Id", "TEXT", optixServeCoreModelsUserTableBase);
optixServeCoreModelsUserTableBase.Columns.Add("Id", idColumnBase);
var passwordColumnBase = new ColumnBase<ColumnMappingBase>("Password", "TEXT", optixServeCoreModelsUserTableBase)
{
IsNullable = true
};
optixServeCoreModelsUserTableBase.Columns.Add("Password", passwordColumnBase);
var privilegeGroupColumnBase = new ColumnBase<ColumnMappingBase>("PrivilegeGroup", "INTEGER", optixServeCoreModelsUserTableBase);
optixServeCoreModelsUserTableBase.Columns.Add("PrivilegeGroup", privilegeGroupColumnBase);
var userNameColumnBase = new ColumnBase<ColumnMappingBase>("UserName", "TEXT", optixServeCoreModelsUserTableBase);
optixServeCoreModelsUserTableBase.Columns.Add("UserName", userNameColumnBase);
relationalModel.DefaultTables.Add("OptixServe.Core.Models.User", optixServeCoreModelsUserTableBase);
var optixServeCoreModelsUserMappingBase = new TableMappingBase<ColumnMappingBase>(user, optixServeCoreModelsUserTableBase, null);
optixServeCoreModelsUserTableBase.AddTypeMapping(optixServeCoreModelsUserMappingBase, false);
defaultTableMappings.Add(optixServeCoreModelsUserMappingBase);
RelationalModel.CreateColumnMapping((ColumnBase<ColumnMappingBase>)idColumnBase, user.FindProperty("Id")!, optixServeCoreModelsUserMappingBase);
RelationalModel.CreateColumnMapping((ColumnBase<ColumnMappingBase>)passwordColumnBase, user.FindProperty("Password")!, optixServeCoreModelsUserMappingBase);
RelationalModel.CreateColumnMapping((ColumnBase<ColumnMappingBase>)privilegeGroupColumnBase, user.FindProperty("PrivilegeGroup")!, optixServeCoreModelsUserMappingBase);
RelationalModel.CreateColumnMapping((ColumnBase<ColumnMappingBase>)userNameColumnBase, user.FindProperty("UserName")!, optixServeCoreModelsUserMappingBase);
var tableMappings = new List<TableMapping>();
user.SetRuntimeAnnotation("Relational:TableMappings", tableMappings);
var usersTable = new Table("Users", null, relationalModel);
var idColumn = new Column("Id", "TEXT", usersTable);
usersTable.Columns.Add("Id", idColumn);
idColumn.Accessors = ColumnAccessorsFactory.CreateGeneric<string>(idColumn);
var passwordColumn = new Column("Password", "TEXT", usersTable)
{
IsNullable = true
};
usersTable.Columns.Add("Password", passwordColumn);
passwordColumn.Accessors = ColumnAccessorsFactory.CreateGeneric<string>(passwordColumn);
var privilegeGroupColumn = new Column("PrivilegeGroup", "INTEGER", usersTable);
usersTable.Columns.Add("PrivilegeGroup", privilegeGroupColumn);
privilegeGroupColumn.Accessors = ColumnAccessorsFactory.CreateGeneric<int>(privilegeGroupColumn);
var userNameColumn = new Column("UserName", "TEXT", usersTable);
usersTable.Columns.Add("UserName", userNameColumn);
userNameColumn.Accessors = ColumnAccessorsFactory.CreateGeneric<string>(userNameColumn);
relationalModel.Tables.Add(("Users", null), usersTable);
var usersTableMapping = new TableMapping(user, usersTable, null);
usersTable.AddTypeMapping(usersTableMapping, false);
tableMappings.Add(usersTableMapping);
RelationalModel.CreateColumnMapping(idColumn, user.FindProperty("Id")!, usersTableMapping);
RelationalModel.CreateColumnMapping(passwordColumn, user.FindProperty("Password")!, usersTableMapping);
RelationalModel.CreateColumnMapping(privilegeGroupColumn, user.FindProperty("PrivilegeGroup")!, usersTableMapping);
RelationalModel.CreateColumnMapping(userNameColumn, user.FindProperty("UserName")!, usersTableMapping);
var pK_Users = new UniqueConstraint("PK_Users", usersTable, new[] { idColumn });
usersTable.PrimaryKey = pK_Users;
pK_Users.SetRowKeyValueFactory(new SimpleRowKeyValueFactory<string>(pK_Users));
var pK_UsersKey = RelationalModel.GetKey(this,
"OptixServe.Core.Models.User",
new[] { "Id" });
pK_Users.MappedKeys.Add(pK_UsersKey);
RelationalModel.GetOrCreateUniqueConstraints(pK_UsersKey).Add(pK_Users);
usersTable.UniqueConstraints.Add("PK_Users", pK_Users);
return relationalModel.MakeReadOnly();
}
}
}

View File

@ -0,0 +1,227 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Json;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using OptixServe.Core.Models;
#pragma warning disable 219, 612, 618
#nullable disable
namespace OptixServe.Infrastructure.Data.CompiledModels
{
[EntityFrameworkInternal]
public partial class UserEntityType
{
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null)
{
var runtimeEntityType = model.AddEntityType(
"OptixServe.Core.Models.User",
typeof(User),
baseEntityType,
propertyCount: 4,
keyCount: 1);
var id = runtimeEntityType.AddProperty(
"Id",
typeof(string),
propertyInfo: typeof(User).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(User).GetField("<Id>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
afterSaveBehavior: PropertySaveBehavior.Throw);
id.SetGetter(
string (User entity) => UserUnsafeAccessors.Id(entity),
bool (User entity) => UserUnsafeAccessors.Id(entity) == null,
string (User instance) => UserUnsafeAccessors.Id(instance),
bool (User instance) => UserUnsafeAccessors.Id(instance) == null);
id.SetSetter(
(User entity, string value) => UserUnsafeAccessors.Id(entity) = value);
id.SetMaterializationSetter(
(User entity, string value) => UserUnsafeAccessors.Id(entity) = value);
id.SetAccessors(
string (InternalEntityEntry entry) => UserUnsafeAccessors.Id(((User)(entry.Entity))),
string (InternalEntityEntry entry) => UserUnsafeAccessors.Id(((User)(entry.Entity))),
string (InternalEntityEntry entry) => entry.ReadOriginalValue<string>(id, 0),
string (InternalEntityEntry entry) => entry.ReadRelationshipSnapshotValue<string>(id, 0),
object (ValueBuffer valueBuffer) => valueBuffer[0]);
id.SetPropertyIndexes(
index: 0,
originalValueIndex: 0,
shadowIndex: -1,
relationshipIndex: 0,
storeGenerationIndex: -1);
id.TypeMapping = SqliteStringTypeMapping.Default;
id.SetCurrentValueComparer(new EntryCurrentValueComparer<string>(id));
var password = runtimeEntityType.AddProperty(
"Password",
typeof(string),
propertyInfo: typeof(User).GetProperty("Password", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(User).GetField("<Password>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
nullable: true);
password.SetGetter(
string (User entity) => UserUnsafeAccessors.Password(entity),
bool (User entity) => UserUnsafeAccessors.Password(entity) == null,
string (User instance) => UserUnsafeAccessors.Password(instance),
bool (User instance) => UserUnsafeAccessors.Password(instance) == null);
password.SetSetter(
(User entity, string value) => UserUnsafeAccessors.Password(entity) = value);
password.SetMaterializationSetter(
(User entity, string value) => UserUnsafeAccessors.Password(entity) = value);
password.SetAccessors(
string (InternalEntityEntry entry) => UserUnsafeAccessors.Password(((User)(entry.Entity))),
string (InternalEntityEntry entry) => UserUnsafeAccessors.Password(((User)(entry.Entity))),
string (InternalEntityEntry entry) => entry.ReadOriginalValue<string>(password, 1),
string (InternalEntityEntry entry) => entry.GetCurrentValue<string>(password),
object (ValueBuffer valueBuffer) => valueBuffer[1]);
password.SetPropertyIndexes(
index: 1,
originalValueIndex: 1,
shadowIndex: -1,
relationshipIndex: -1,
storeGenerationIndex: -1);
password.TypeMapping = SqliteStringTypeMapping.Default;
var privilegeGroup = runtimeEntityType.AddProperty(
"PrivilegeGroup",
typeof(PrivilegeGroup),
propertyInfo: typeof(User).GetProperty("PrivilegeGroup", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(User).GetField("<PrivilegeGroup>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
privilegeGroup.SetGetter(
PrivilegeGroup (User entity) => UserUnsafeAccessors.PrivilegeGroup(entity),
bool (User entity) => object.Equals(((object)(UserUnsafeAccessors.PrivilegeGroup(entity))), ((object)(PrivilegeGroup.Admin))),
PrivilegeGroup (User instance) => UserUnsafeAccessors.PrivilegeGroup(instance),
bool (User instance) => object.Equals(((object)(UserUnsafeAccessors.PrivilegeGroup(instance))), ((object)(PrivilegeGroup.Admin))));
privilegeGroup.SetSetter(
(User entity, PrivilegeGroup value) => UserUnsafeAccessors.PrivilegeGroup(entity) = value);
privilegeGroup.SetMaterializationSetter(
(User entity, PrivilegeGroup value) => UserUnsafeAccessors.PrivilegeGroup(entity) = value);
privilegeGroup.SetAccessors(
PrivilegeGroup (InternalEntityEntry entry) => UserUnsafeAccessors.PrivilegeGroup(((User)(entry.Entity))),
PrivilegeGroup (InternalEntityEntry entry) => UserUnsafeAccessors.PrivilegeGroup(((User)(entry.Entity))),
PrivilegeGroup (InternalEntityEntry entry) => entry.ReadOriginalValue<PrivilegeGroup>(privilegeGroup, 2),
PrivilegeGroup (InternalEntityEntry entry) => entry.GetCurrentValue<PrivilegeGroup>(privilegeGroup),
object (ValueBuffer valueBuffer) => valueBuffer[2]);
privilegeGroup.SetPropertyIndexes(
index: 2,
originalValueIndex: 2,
shadowIndex: -1,
relationshipIndex: -1,
storeGenerationIndex: -1);
privilegeGroup.TypeMapping = IntTypeMapping.Default.Clone(
comparer: new ValueComparer<PrivilegeGroup>(
bool (PrivilegeGroup v1, PrivilegeGroup v2) => object.Equals(((object)(v1)), ((object)(v2))),
int (PrivilegeGroup v) => ((object)v).GetHashCode(),
PrivilegeGroup (PrivilegeGroup v) => v),
keyComparer: new ValueComparer<PrivilegeGroup>(
bool (PrivilegeGroup v1, PrivilegeGroup v2) => object.Equals(((object)(v1)), ((object)(v2))),
int (PrivilegeGroup v) => ((object)v).GetHashCode(),
PrivilegeGroup (PrivilegeGroup v) => v),
providerValueComparer: new ValueComparer<int>(
bool (int v1, int v2) => v1 == v2,
int (int v) => v,
int (int v) => v),
mappingInfo: new RelationalTypeMappingInfo(
storeTypeName: "INTEGER"),
converter: new ValueConverter<PrivilegeGroup, int>(
int (PrivilegeGroup value) => ((int)(value)),
PrivilegeGroup (int value) => ((PrivilegeGroup)(value))),
jsonValueReaderWriter: new JsonConvertedValueReaderWriter<PrivilegeGroup, int>(
JsonInt32ReaderWriter.Instance,
new ValueConverter<PrivilegeGroup, int>(
int (PrivilegeGroup value) => ((int)(value)),
PrivilegeGroup (int value) => ((PrivilegeGroup)(value)))));
privilegeGroup.SetSentinelFromProviderValue(0);
var userName = runtimeEntityType.AddProperty(
"UserName",
typeof(string),
propertyInfo: typeof(User).GetProperty("UserName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(User).GetField("<UserName>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
userName.SetGetter(
string (User entity) => UserUnsafeAccessors.UserName(entity),
bool (User entity) => UserUnsafeAccessors.UserName(entity) == null,
string (User instance) => UserUnsafeAccessors.UserName(instance),
bool (User instance) => UserUnsafeAccessors.UserName(instance) == null);
userName.SetSetter(
(User entity, string value) => UserUnsafeAccessors.UserName(entity) = value);
userName.SetMaterializationSetter(
(User entity, string value) => UserUnsafeAccessors.UserName(entity) = value);
userName.SetAccessors(
string (InternalEntityEntry entry) => UserUnsafeAccessors.UserName(((User)(entry.Entity))),
string (InternalEntityEntry entry) => UserUnsafeAccessors.UserName(((User)(entry.Entity))),
string (InternalEntityEntry entry) => entry.ReadOriginalValue<string>(userName, 3),
string (InternalEntityEntry entry) => entry.GetCurrentValue<string>(userName),
object (ValueBuffer valueBuffer) => valueBuffer[3]);
userName.SetPropertyIndexes(
index: 3,
originalValueIndex: 3,
shadowIndex: -1,
relationshipIndex: -1,
storeGenerationIndex: -1);
userName.TypeMapping = SqliteStringTypeMapping.Default;
var key = runtimeEntityType.AddKey(
new[] { id });
runtimeEntityType.SetPrimaryKey(key);
return runtimeEntityType;
}
public static void CreateAnnotations(RuntimeEntityType runtimeEntityType)
{
var id = runtimeEntityType.FindProperty("Id");
var password = runtimeEntityType.FindProperty("Password");
var privilegeGroup = runtimeEntityType.FindProperty("PrivilegeGroup");
var userName = runtimeEntityType.FindProperty("UserName");
var key = runtimeEntityType.FindKey(new[] { id });
key.SetPrincipalKeyValueFactory(KeyValueFactoryFactory.CreateSimpleNullableFactory<string, int>(key));
key.SetIdentityMapFactory(IdentityMapFactoryFactory.CreateFactory<string>(key));
runtimeEntityType.SetOriginalValuesFactory(
ISnapshot (InternalEntityEntry source) =>
{
var entity = ((User)(source.Entity));
return ((ISnapshot)(new Snapshot<string, string, PrivilegeGroup, string>((source.GetCurrentValue<string>(id) == null ? null : ((ValueComparer<string>)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue<string>(id))), (source.GetCurrentValue<string>(password) == null ? null : ((ValueComparer<string>)(((IProperty)password).GetValueComparer())).Snapshot(source.GetCurrentValue<string>(password))), ((ValueComparer<PrivilegeGroup>)(((IProperty)privilegeGroup).GetValueComparer())).Snapshot(source.GetCurrentValue<PrivilegeGroup>(privilegeGroup)), (source.GetCurrentValue<string>(userName) == null ? null : ((ValueComparer<string>)(((IProperty)userName).GetValueComparer())).Snapshot(source.GetCurrentValue<string>(userName))))));
});
runtimeEntityType.SetStoreGeneratedValuesFactory(
ISnapshot () => Snapshot.Empty);
runtimeEntityType.SetTemporaryValuesFactory(
ISnapshot (InternalEntityEntry source) => Snapshot.Empty);
runtimeEntityType.SetShadowValuesFactory(
ISnapshot (IDictionary<string, object> source) => Snapshot.Empty);
runtimeEntityType.SetEmptyShadowValuesFactory(
ISnapshot () => Snapshot.Empty);
runtimeEntityType.SetRelationshipSnapshotFactory(
ISnapshot (InternalEntityEntry source) =>
{
var entity = ((User)(source.Entity));
return ((ISnapshot)(new Snapshot<string>((source.GetCurrentValue<string>(id) == null ? null : ((ValueComparer<string>)(((IProperty)id).GetKeyValueComparer())).Snapshot(source.GetCurrentValue<string>(id))))));
});
runtimeEntityType.Counts = new PropertyCounts(
propertyCount: 4,
navigationCount: 0,
complexPropertyCount: 0,
originalValueCount: 4,
shadowCount: 0,
relationshipCount: 1,
storeGeneratedCount: 0);
runtimeEntityType.AddAnnotation("Relational:FunctionName", null);
runtimeEntityType.AddAnnotation("Relational:Schema", null);
runtimeEntityType.AddAnnotation("Relational:SqlQuery", null);
runtimeEntityType.AddAnnotation("Relational:TableName", "Users");
runtimeEntityType.AddAnnotation("Relational:ViewName", null);
runtimeEntityType.AddAnnotation("Relational:ViewSchema", null);
Customize(runtimeEntityType);
}
static partial void Customize(RuntimeEntityType runtimeEntityType);
}
}

View File

@ -0,0 +1,25 @@
// <auto-generated />
using System;
using System.Runtime.CompilerServices;
using OptixServe.Core.Models;
#pragma warning disable 219, 612, 618
#nullable disable
namespace OptixServe.Infrastructure.Data.CompiledModels
{
public static class UserUnsafeAccessors
{
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<Id>k__BackingField")]
public static extern ref string Id(User @this);
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<Password>k__BackingField")]
public static extern ref string Password(User @this);
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<PrivilegeGroup>k__BackingField")]
public static extern ref PrivilegeGroup PrivilegeGroup(User @this);
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<UserName>k__BackingField")]
public static extern ref string UserName(User @this);
}
}

View File

@ -0,0 +1,82 @@
# EFCore Intergration
## Introduction
This app relies on EF Core to access the database.
However, it is NOT so smooth when work with NativeAOT.
To use EF Core, see below.
## DesignTimeDbContextFactory
To work with NativeAOT, a code-defined way to create DbContext instance is a MUST in nearly ALL operations of EF Core, letting ef tool discover the DbContext.
In this project, `OptixServe.Infrastructure/Utilites/DesignTimeDbContextFactory.cs` is set up to do this.
This class implements a simple commandline arguments parser, enabling passing arguments along with `dotnet ef`.
Currently, there are two options, `--config/-c` and `--data-dir/-d` are supported. See documents there.
To pass arguments/options to `CreateDbContext` static method, pass the arguments following with `dotnet ef` command, with two dashes splitting.
For example:
```bash
dotnet ef database update -- -c ../data/appsettings.Development.json -d ../data/
```
## Workflow
To make the code work, following the steps:
1. Implement other parts
2. Compile the data models, with `--nativeaot` option.
3. Add migration
4. Update database
5. Build project, and Run!
Here are the details.
### Requirements
See [https://learn.microsoft.com/en-us/ef/core/performance/nativeaot-and-precompiled-queries]()
### Compile Models
```bash
dotnet ef dbcontext optimize --output-dir Data/CompiledModels --precompile-queries --nativeaot -- -c ../data_dev/appsettings.Development.json -d ../data_dev/
```
If this is the first time to run `dbcontext optimize`, DO NOT forget to `UseModel` in DbContext construction.
```cs OptixServe.Infrastructure/Utilites/DatabaseHelper.cs
public static void ConfigureDbContext(DbContextOptionsBuilder options)
{
// ...
options.UseSqlite(connectionString, b => b.MigrationsAssembly("OptixServe.Infrastructure"))
.UseModel(AppDbContextModel.Instance);
// ...
}
```
### Add Migration
```bash
dotnet ef migrations add InitialCreate -- -c ../data_dev/appsettings.Development.json
```
### Update Database
```bash
dotnet ef database update -- -c ../data_dev/appsettings.Development.json -d ../data_dev/
```
### Build Project
```bash
dotnet publish -c Release -r linux-x64
```

View File

@ -9,6 +9,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tasks" Version="9.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.6" /> <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.6" /> <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.6" />
@ -20,6 +24,7 @@
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<InterceptorsNamespaces>$(InterceptorsNamespaces);Microsoft.EntityFrameworkCore.GeneratedInterceptors</InterceptorsNamespaces>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using OptixServe.Infrastructure.Configuration; using OptixServe.Infrastructure.Configuration;
using OptixServe.Infrastructure.Data.CompiledModels;
namespace OptixServe.Infrastructure.Utilites; namespace OptixServe.Infrastructure.Utilites;
@ -22,7 +23,8 @@ public static class DatabaseHelper
var dbPath = dbSettings.Host ?? "optixserve.db"; var dbPath = dbSettings.Host ?? "optixserve.db";
var connectionString = $"Data Source={dbPath}"; var connectionString = $"Data Source={dbPath}";
options.UseSqlite(connectionString, b => b.MigrationsAssembly("OptixServe.Infrastructure")); options.UseSqlite(connectionString, b => b.MigrationsAssembly("OptixServe.Infrastructure"))
.UseModel(AppDbContextModel.Instance);
} }
else else