dotnet / EntityFramework.Docs

Documentation for Entity Framework Core and Entity Framework 6
https://docs.microsoft.com/ef/
Creative Commons Attribution 4.0 International
1.59k stars 1.95k forks source link

Documemt how do generate migrations for an Blazor WASM app #4230

Open tysongibby opened 1 year ago

tysongibby commented 1 year ago

Thank you for looking at this issue.

I have not yet been able to get this project to successfully create the first SQLite database migration. Link to the repo for my full code

Eric Sink on the SQLitePCL.raw project thought this may be an issue related to EfCore.

I am receiving the error "The specified deps.json [C:\git\ThePlayer\ThePlayer\Client\bin\Debug\net6.0\ThePlayer.Client.deps.json] does not exist" when I run the database migration command "add-migration initial"

I am using the following: SQLitePCLRaw version 2.1.3 nuget package: SQLitePCLRaw.bundle_e_sqlite3 Microsoft.EntityFrameworkCore.Sqlite.Core version 6.0.12

Visual Studio 2022 17.43, .NET 6 Blazor WASM, Windows 11 Pro 22H2 22621.963, Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz 2.59 GHz

Target framework:
.NET 6, Blazor WASM, client browser

These are the packages currently referenced in my project:

  <ItemGroup>    
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.12" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.12" PrivateAssets="all" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="6.0.12" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.12">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.3" />
  </ItemGroup>

output from rebuild:

Rebuild started...
1>------ Rebuild All started: Project: ThePlayer.Shared, Configuration: Debug Any CPU ------
Restored C:\git\ThePlayer\ThePlayer\Server\ThePlayer.Server.csproj (in 43 ms).
Restored C:\git\ThePlayer\ThePlayer\Client\ThePlayer.Client.csproj (in 44 ms).
Restored C:\git\ThePlayer\ThePlayer\Shared\ThePlayer.Shared.csproj (in 43 ms).
1>ThePlayer.Shared -> C:\git\ThePlayer\ThePlayer\Shared\bin\Debug\net6.0\ThePlayer.Shared.dll
2>------ Rebuild All started: Project: ThePlayer.Client, Configuration: Debug Any CPU ------
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning : Found a native function (sqlite3_config) with varargs in e_sqlite3. Calling such functions is not supported, and will fail at runtime. Managed DllImports: 
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_config_none(System.Int32) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_config_int(System.Int32, System.Int32) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_config_int_arm64cc(System.Int32, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.Int32) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_config_log(System.Int32, System.IntPtr, SQLitePCL.hook_handle) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_config_log_arm64cc(System.Int32, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, SQLitePCL.hook_handle) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning : Found a native function (sqlite3_db_config) with varargs in e_sqlite3. Calling such functions is not supported, and will fail at runtime. Managed DllImports: 
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_charptr(SQLitePCL.sqlite3, System.Int32, System.Byte*) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_charptr_arm64cc(SQLitePCL.sqlite3, System.Int32, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.Byte*) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_int_outint(SQLitePCL.sqlite3, System.Int32, System.Int32, System.Int32*) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_int_outint_arm64cc(SQLitePCL.sqlite3, System.Int32, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.Int32, System.Int32*) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_intptr_int_int(SQLitePCL.sqlite3, System.Int32, System.IntPtr, System.Int32, System.Int32) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_intptr_int_int_arm64cc(SQLitePCL.sqlite3, System.Int32, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.Int32, System.Int32) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>Compiling native assets with emcc. This may take a while ...
2>[1/3] pinvoke.c -> pinvoke.o [took 0.38s]
2>[2/3] corebindings.c -> corebindings.o [took 0.46s]
2>[3/3] driver.c -> driver.o [took 0.56s]
2>Linking with emcc. This may take a while ...
2> "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\bin\wasm-ld.exe" -o C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\dotnet.wasm C:\Users\tyson.LAPPY9000\.nuget\packages\sqlitepclraw.lib.e_sqlite3\2.1.3\buildTransitive\net6.0\..\..\runtimes\browser-wasm\nativeassets\net6.0\e_sqlite3.a C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\pinvoke.o C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\driver.o C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\corebindings.o "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libicui18n.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libicuuc.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-component-debugger-static.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-component-diagnostics_tracing-stub-static.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-component-hot_reload-static.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-ee-interp.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-icall-table.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-ilgen.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-profiler-aot.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmonosgen-2.0.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libSystem.IO.Compression.Native.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libSystem.Native.a" "-LC:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libgl.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libal.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libhtml5.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++abi.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libdlmalloc.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libsockets.a" -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --export putchar --export stackSave --export stackRestore --export stackAlloc --export __wasm_call_ctors --export __errno_location --export malloc --export free --export __cxa_is_pointer_type --export __cxa_can_catch --export setThrew --export _get_tzname --export _get_daylight --export _get_timezone --export memalign --export memset --export emscripten_main_thread_process_queued_calls --export ntohs --export htons --export htonl --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-table -z stack-size=5242880 --initial-memory=536870912 --no-entry --max-memory=2147483648 --global-base=1024
2> "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\bin\wasm-emscripten-finalize" --minimize-wasm-changes -g --dyncalls-i64 --dwarf C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\dotnet.wasm -o C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\dotnet.wasm --detect-features
2> "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Node.win-x64\6.0.12\tools\bin\node.exe" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\src\compiler.js" C:\Users\TYSON~1.LAP\AppData\Local\Temp\tmppxf580an.txt
2> "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\bin\llvm-objcopy.exe" C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\dotnet.wasm C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\dotnet.wasm --remove-section=producers
2>Optimizing dotnet.wasm ...
2>ThePlayer.Client -> C:\git\ThePlayer\ThePlayer\Client\bin\Debug\net6.0\ThePlayer.Client.dll
2>ThePlayer.Client (Blazor output) -> C:\git\ThePlayer\ThePlayer\Client\bin\Debug\net6.0\wwwroot
2>Done building project "ThePlayer.Client.csproj".
3>------ Rebuild All started: Project: ThePlayer.Server, Configuration: Debug Any CPU ------
3>ThePlayer.Server -> C:\git\ThePlayer\ThePlayer\Server\bin\Debug\net6.0\ThePlayer.Server.dll
========== Rebuild All: 3 succeeded, 0 failed, 0 skipped ==========
========== Elapsed 00:18.020 ==========
ajcvickers commented 1 year ago

@bricelam This is a deps.json case which is fully reproducible on my machine and doesn't go away after a full clean and rebuild. Also, the build outside of dotnet ef works fine. Any ideas?

ErikEJ commented 1 year ago

I think this is failing because ThePlayer.Cleient is a wasm client project with no deps.json file and can not be executed by dotnet exec.

Maybe the SDK type could be detected and some actionable error message given, with a docs link.

tysongibby commented 1 year ago

@ErikEJ & @bricelam Thanks for looking at this. Is there a work-around I could be implementing or something different I can be doing for now?

tysongibby commented 1 year ago

@ErikEJ & @bricelam updated to 2.1.4, still having the same issue.

ajcvickers commented 1 year ago

@tysongibby The workaround is to create a separate console application project in the solution. This project is used only to enable the EF tools to create an appropriate context instance. The project needs to reference the project containing your DbContext and the EF Core database provider you are using. For example:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="6.0.12" />
        <PackageReference Include="SQLitePCLRaw.core" Version="2.1.3" />
        <PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="2.1.3" />
        <PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.1.3" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\ThePlayer\Shared\ThePlayer.Shared.csproj" />
    </ItemGroup>

</Project>

The console application needs to have an IDesignTimeDbContextFactory. Something like this:

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using ThePlayer.Shared.Data.Context;

Console.WriteLine("Hello, World!");

public class ContextFactory : IDesignTimeDbContextFactory<ThePlayerContext>
{
    public ThePlayerContext CreateDbContext(string[] args) 
        => new(null, new DbContextOptionsBuilder<ThePlayerContext>().UseSqlite(args[0]).Options);
}

This can then be used to generate migrations from the command line. For example:

PS C:\local\code\repros\ThePlayer-master\ThePlayer-master\ConsoleApp1> dotnet ef migrations add One --project ..\ThePlayer\Shared\ThePlayer.Shared.csproj -- "DataSource=ThePlayer.db"
Build started...
Build succeeded.
Done. To undo this action, use 'ef migrations remove'
PS C:\local\code\repros\ThePlayer-master\ThePlayer-master\ConsoleApp1>
ErikEJ commented 1 year ago

@ajcvickers Docs enhancement?

tysongibby commented 1 year ago

Thanks, I'll implement that tonight after work.

tysongibby commented 1 year ago

@ajcvickers Thanks for the work-around. When I set things up the way you suggest I am getting the error Exception has been thrown by the target of an invocation. This is the output from my migration:

PM> add-migration initial
Build started...
Build succeeded.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at ContextFactory.CreateDbContext(String[] args) in C:\git\ThePlayer\SqlLiteEf\Program.cs:line 12
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContextFromFactory(Type factory, Type contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_2.<FindContextTypes>b__9()
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Exception has been thrown by the target of an invocation.
ajcvickers commented 1 year ago

@tysongibby In my example I set it up to take the connection string from the command line. Looks like you are not passing it. The connection string doesn't have to come from the command line, but then you shouldn't be trying to get it out of args.

tysongibby commented 1 year ago

@ajcvickers Thanks for your help and your patience. I am obviously doing something wrong implementing the work-around. I am getting an error where it can't find the dbcontext:

dotnet ef migrations add One --project ..\ThePlayer\ThePlayer\Shared\ThePlayer.Shared.csproj -- "DataSource=ThePlayer.db"
Build started...
Build succeeded.
The Entity Framework tools version '6.0.12' is older than that of the runtime '6.0.13'. Update the tools for the latest features and bug fixes. See https://aka.ms/AAc1fbw for more information.
System.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, DbContextOptions contextOptions, DbContext context)
   at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
   at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

updated the code in the repo: https://github.com/tysongibby/ThePlayer

Locxion commented 1 year ago

@ajcvickers Thanks for your help and your patience. I am obviously doing something wrong implementing the work-around. I am getting an error where it can't find the dbcontext:

dotnet ef migrations add One --project ..\ThePlayer\ThePlayer\Shared\ThePlayer.Shared.csproj -- "DataSource=ThePlayer.db"
Build started...
Build succeeded.
The Entity Framework tools version '6.0.12' is older than that of the runtime '6.0.13'. Update the tools for the latest features and bug fixes. See https://aka.ms/AAc1fbw for more information.
System.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, DbContextOptions contextOptions, DbContext context)
   at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
   at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

updated the code in the repo: https://github.com/tysongibby/ThePlayer

did you had any luck with the workaround? im trying to build a .net maui blazor app with ef and sqlite and having problems with adding my first migration