SapientGuardian.EntityFrameworkCore.MySql
SapientGuardian.EntityFrameworkCore.MySql copied to clipboard
"dotnet ef dbcontext scaffold" command: Which provider name?
I would like to create my DbContext from an existing MySQL database. MS describes this for SQL Server here. I tried some provider names like MySQL.Data.Entity.MySQLDatabaseProvider, MySQL.Data.Entity, SapientGuardian.EntityFrameworkCore. ..., but none of them worked. Error "Could not find provider". Please give me a hint for this issue. Thank you
I don't believe reverse engineering a DB is supported by this library at this time. Giving the assembly name of SapientGuardian.EntityFrameworkCore.MySql resulted in
System.AggregateException: One or more errors occurred. (Unable to find expected assembly attribute named DesignTimeProviderServicesAttribute in provider assembly SapientGuardian.EntityFrameworkCore.MySql. This attribute is required to identify the class which acts as the design-time service provider factory.) ---> System.InvalidOperationException: Unable to find expected assembly attribute named DesignTimeProviderServicesAttribute in provider assembly SapientGuardian.EntityFrameworkCore.MySql. This attribute is required to identify the class which acts as the design-time service provider factory.
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.<ExecuteAsync>d__1.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
---> (Inner Exception #0) System.InvalidOperationException: Unable to find expected assembly attribute named DesignTimeProviderServicesAttribute in provider assembly SapientGuardian.EntityFrameworkCore.MySql. This attribute is required to identify the class which acts as the design-time service provider factory.
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.<ExecuteAsync>d__1.MoveNext()<---
One or more errors occurred. (Unable to find expected assembly attribute named DesignTimeProviderServicesAttribute in provider assembly SapientGuardian.EntityFrameworkCore.MySql. This attribute is required to identify the class which acts as the design-time service provider factory.)
And sure enough, we don't have DesignTimeProviderServicesAttribute anywhere in the source tree that I could find. You might try your luck with the recently-released official mysql ef core library, https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/
Unfortunately, it is not working with the official packages yet (same error)...
After much of the exact same grief with the DesignTimeProviderServicesAttribute error on scaffolding, I was able to reverse engineer a MySQL database using a different provider: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql
I ran across this provider on the microsoft docs site https://docs.microsoft.com/en-us/ef/core/providers/pomelo/. Good luck!
@lindeberg Assuming you have both Pomelo.EntityFrameworkCore.MySql and Pomelo.EntityFrameworkCore.MySql.Design installed, have you tried restarting VS? I think you should be pretty much good to go with what you have there. Your command looks about the same as mine:
Scaffold-DbContext "server=server;userid=user;pwd=pass;port=3306;database=db;sslmode=none;" Pomelo.EntityFrameworkCore.MySql -o Models/subfolder
@rbudnar Sorry, and thank you, didn't have .Design, been a long day. By the way, it's been a while since you used this - do you think it's production ready?
@lindeberg I've been using it for a while and haven't run into any real issues with it - of course I'm doing anything huge with it either, but it has been working well for me. Maybe take a look at their issues and see if anything there is a red flag for you? https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues Of course, I don't want to spam up this repo talking about another one, my apologies :)