diff --git a/Pal.Client/Database/Compiled/ClientLocationEntityType.cs b/Pal.Client/Database/Compiled/ClientLocationEntityType.cs new file mode 100644 index 0000000..809cbc5 --- /dev/null +++ b/Pal.Client/Database/Compiled/ClientLocationEntityType.cs @@ -0,0 +1,123 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Pal.Client.Database.Compiled +{ + internal partial class ClientLocationEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Pal.Client.Database.ClientLocation", + typeof(ClientLocation), + baseEntityType); + + var localId = runtimeEntityType.AddProperty( + "LocalId", + typeof(int), + propertyInfo: typeof(ClientLocation).GetProperty("LocalId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var seen = runtimeEntityType.AddProperty( + "Seen", + typeof(bool), + propertyInfo: typeof(ClientLocation).GetProperty("Seen", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var sinceVersion = runtimeEntityType.AddProperty( + "SinceVersion", + typeof(string), + propertyInfo: typeof(ClientLocation).GetProperty("SinceVersion", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var source = runtimeEntityType.AddProperty( + "Source", + typeof(ClientLocation.ESource), + propertyInfo: typeof(ClientLocation).GetProperty("Source", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var territoryType = runtimeEntityType.AddProperty( + "TerritoryType", + typeof(ushort), + propertyInfo: typeof(ClientLocation).GetProperty("TerritoryType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var type = runtimeEntityType.AddProperty( + "Type", + typeof(ClientLocation.EType), + propertyInfo: typeof(ClientLocation).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var x = runtimeEntityType.AddProperty( + "X", + typeof(float), + propertyInfo: typeof(ClientLocation).GetProperty("X", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var y = runtimeEntityType.AddProperty( + "Y", + typeof(float), + propertyInfo: typeof(ClientLocation).GetProperty("Y", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var z = runtimeEntityType.AddProperty( + "Z", + typeof(float), + propertyInfo: typeof(ClientLocation).GetProperty("Z", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { localId }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeSkipNavigation CreateSkipNavigation1(RuntimeEntityType declaringEntityType, RuntimeEntityType targetEntityType, RuntimeEntityType joinEntityType) + { + var skipNavigation = declaringEntityType.AddSkipNavigation( + "ImportedBy", + targetEntityType, + joinEntityType.FindForeignKey( + new[] { joinEntityType.FindProperty("ImportedLocationsLocalId")! }, + declaringEntityType.FindKey(new[] { declaringEntityType.FindProperty("LocalId")! })!, + declaringEntityType)!, + true, + false, + typeof(List), + propertyInfo: typeof(ClientLocation).GetProperty("ImportedBy", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var inverse = targetEntityType.FindSkipNavigation("ImportedLocations"); + if (inverse != null) + { + skipNavigation.Inverse = inverse; + inverse.Inverse = skipNavigation; + } + + return skipNavigation; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Locations"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Pal.Client/Database/Compiled/ClientLocationImportHistoryEntityType.cs b/Pal.Client/Database/Compiled/ClientLocationImportHistoryEntityType.cs new file mode 100644 index 0000000..2b15bab --- /dev/null +++ b/Pal.Client/Database/Compiled/ClientLocationImportHistoryEntityType.cs @@ -0,0 +1,83 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Pal.Client.Database.Compiled +{ + internal partial class ClientLocationImportHistoryEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "ClientLocationImportHistory", + typeof(Dictionary), + baseEntityType, + sharedClrType: true, + indexerPropertyInfo: RuntimeEntityType.FindIndexerProperty(typeof(Dictionary)), + propertyBag: true); + + var importedById = runtimeEntityType.AddProperty( + "ImportedById", + typeof(Guid), + propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var importedLocationsLocalId = runtimeEntityType.AddProperty( + "ImportedLocationsLocalId", + typeof(int), + propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(), + afterSaveBehavior: PropertySaveBehavior.Throw); + + var key = runtimeEntityType.AddKey( + new[] { importedById, importedLocationsLocalId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { importedLocationsLocalId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ImportedById")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ImportedLocationsLocalId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("LocalId")! })!, + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "LocationImports"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Pal.Client/Database/Compiled/ImportHistoryEntityType.cs b/Pal.Client/Database/Compiled/ImportHistoryEntityType.cs new file mode 100644 index 0000000..c3f25d8 --- /dev/null +++ b/Pal.Client/Database/Compiled/ImportHistoryEntityType.cs @@ -0,0 +1,94 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Pal.Client.Database.Compiled +{ + internal partial class ImportHistoryEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Pal.Client.Database.ImportHistory", + typeof(ImportHistory), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(Guid), + propertyInfo: typeof(ImportHistory).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ImportHistory).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var exportedAt = runtimeEntityType.AddProperty( + "ExportedAt", + typeof(DateTime), + propertyInfo: typeof(ImportHistory).GetProperty("ExportedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ImportHistory).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var importedAt = runtimeEntityType.AddProperty( + "ImportedAt", + typeof(DateTime), + propertyInfo: typeof(ImportHistory).GetProperty("ImportedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ImportHistory).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var remoteUrl = runtimeEntityType.AddProperty( + "RemoteUrl", + typeof(string), + propertyInfo: typeof(ImportHistory).GetProperty("RemoteUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ImportHistory).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static RuntimeSkipNavigation CreateSkipNavigation1(RuntimeEntityType declaringEntityType, RuntimeEntityType targetEntityType, RuntimeEntityType joinEntityType) + { + var skipNavigation = declaringEntityType.AddSkipNavigation( + "ImportedLocations", + targetEntityType, + joinEntityType.FindForeignKey( + new[] { joinEntityType.FindProperty("ImportedById")! }, + declaringEntityType.FindKey(new[] { declaringEntityType.FindProperty("Id")! })!, + declaringEntityType)!, + true, + false, + typeof(List), + propertyInfo: typeof(ImportHistory).GetProperty("ImportedLocations", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ImportHistory).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var inverse = targetEntityType.FindSkipNavigation("ImportedBy"); + if (inverse != null) + { + skipNavigation.Inverse = inverse; + inverse.Inverse = skipNavigation; + } + + return skipNavigation; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Imports"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Pal.Client/Database/Compiled/PalClientContextModel.cs b/Pal.Client/Database/Compiled/PalClientContextModel.cs new file mode 100644 index 0000000..61cf3d0 --- /dev/null +++ b/Pal.Client/Database/Compiled/PalClientContextModel.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Pal.Client.Database.Compiled +{ + [DbContext(typeof(PalClientContext))] + public partial class PalClientContextModel : RuntimeModel + { + static PalClientContextModel() + { + var model = new PalClientContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static PalClientContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/Pal.Client/Database/Compiled/PalClientContextModelBuilder.cs b/Pal.Client/Database/Compiled/PalClientContextModelBuilder.cs new file mode 100644 index 0000000..81f2a22 --- /dev/null +++ b/Pal.Client/Database/Compiled/PalClientContextModelBuilder.cs @@ -0,0 +1,35 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Pal.Client.Database.Compiled +{ + public partial class PalClientContextModel + { + partial void Initialize() + { + var clientLocationImportHistory = ClientLocationImportHistoryEntityType.Create(this); + var clientLocation = ClientLocationEntityType.Create(this); + var importHistory = ImportHistoryEntityType.Create(this); + var remoteEncounter = RemoteEncounterEntityType.Create(this); + + ClientLocationImportHistoryEntityType.CreateForeignKey1(clientLocationImportHistory, importHistory); + ClientLocationImportHistoryEntityType.CreateForeignKey2(clientLocationImportHistory, clientLocation); + RemoteEncounterEntityType.CreateForeignKey1(remoteEncounter, clientLocation); + + ClientLocationEntityType.CreateSkipNavigation1(clientLocation, importHistory, clientLocationImportHistory); + ImportHistoryEntityType.CreateSkipNavigation1(importHistory, clientLocation, clientLocationImportHistory); + + ClientLocationImportHistoryEntityType.CreateAnnotations(clientLocationImportHistory); + ClientLocationEntityType.CreateAnnotations(clientLocation); + ImportHistoryEntityType.CreateAnnotations(importHistory); + RemoteEncounterEntityType.CreateAnnotations(remoteEncounter); + + AddAnnotation("ProductVersion", "7.0.3"); + } + } +} diff --git a/Pal.Client/Database/Compiled/RemoteEncounterEntityType.cs b/Pal.Client/Database/Compiled/RemoteEncounterEntityType.cs new file mode 100644 index 0000000..a2df98b --- /dev/null +++ b/Pal.Client/Database/Compiled/RemoteEncounterEntityType.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Pal.Client.Database.Compiled +{ + internal partial class RemoteEncounterEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Pal.Client.Database.RemoteEncounter", + typeof(RemoteEncounter), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(int), + propertyInfo: typeof(RemoteEncounter).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RemoteEncounter).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueGenerated: ValueGenerated.OnAdd, + afterSaveBehavior: PropertySaveBehavior.Throw); + + var accountId = runtimeEntityType.AddProperty( + "AccountId", + typeof(string), + propertyInfo: typeof(RemoteEncounter).GetProperty("AccountId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RemoteEncounter).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 13); + + var clientLocationId = runtimeEntityType.AddProperty( + "ClientLocationId", + typeof(int), + propertyInfo: typeof(RemoteEncounter).GetProperty("ClientLocationId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RemoteEncounter).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { clientLocationId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("ClientLocationId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("LocalId")! })!, + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var clientLocation = declaringEntityType.AddNavigation("ClientLocation", + runtimeForeignKey, + onDependent: true, + typeof(ClientLocation), + propertyInfo: typeof(RemoteEncounter).GetProperty("ClientLocation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RemoteEncounter).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var remoteEncounters = principalEntityType.AddNavigation("RemoteEncounters", + runtimeForeignKey, + onDependent: false, + typeof(List), + propertyInfo: typeof(ClientLocation).GetProperty("RemoteEncounters", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(ClientLocation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "RemoteEncounters"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Pal.Client/DependencyInjectionContext.cs b/Pal.Client/DependencyInjectionContext.cs index 3a75509..cc967cc 100644 --- a/Pal.Client/DependencyInjectionContext.cs +++ b/Pal.Client/DependencyInjectionContext.cs @@ -99,7 +99,9 @@ namespace Pal.Client typeof(DependencyInjectionContext).Assembly.FullName); // EF core - _serviceCollection.AddDbContext(o => o.UseSqlite(_sqliteConnectionString)); + _serviceCollection.AddDbContext(o => o + .UseSqlite(_sqliteConnectionString) + .UseModel(Database.Compiled.PalClientContextModel.Instance)); _serviceCollection.AddTransient(); _serviceCollection.AddScoped(); diff --git a/Pal.Client/README.md b/Pal.Client/README.md index 52bd208..71ef729 100644 --- a/Pal.Client/README.md +++ b/Pal.Client/README.md @@ -13,3 +13,8 @@ To use with `dotnet ef` commands, specify it as `-c EF`, for example: ```shell dotnet ef migrations add MigrationName --configuration EF ``` + +To rebuild the compiled model: +```shell +dotnet ef dbcontext optimize --output-dir Database/Compiled --namespace Pal.Client.Database.Compiled --configuration EF +```