Övergått till entity framework + lagt till ny tabell
This commit is contained in:
24
GreadyPoang.Migrations/GreadyPoang.Migrations.csproj
Normal file
24
GreadyPoang.Migrations/GreadyPoang.Migrations.csproj
Normal file
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GreadyPoang.DataLayer\GreadyPoang.DataLayer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
30
GreadyPoang.Migrations/Program.cs
Normal file
30
GreadyPoang.Migrations/Program.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using GreadyPoang.DataLayer.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Hosting; // Replace with your actual namespace
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
using var host = CreateHostBuilder(args).Build();
|
||||
|
||||
// Resolve your DbContext
|
||||
var context = host.Services.GetRequiredService<DataContext>();
|
||||
context.Database.EnsureCreated();
|
||||
// Optional: Apply migrations at runtime
|
||||
context.Database.Migrate();
|
||||
|
||||
Console.WriteLine("Migration applied successfully.");
|
||||
}
|
||||
|
||||
static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureServices((_, services) =>
|
||||
{
|
||||
var MauiDataPath = string.Empty;
|
||||
MauiDataPath = File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"));
|
||||
var dbPath = Path.Combine(MauiDataPath, "PoangDB.db");
|
||||
services.AddDbContext<DataContext>(options =>
|
||||
options.UseSqlite($"Data Source={dbPath}"));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user