Bug #90368 EF Core Scaffold from Existing Database - Methods are missing implementation
Submitted: 10 Apr 2018 11:13 Modified: 6 Aug 2018 17:32
Reporter: James Czerwik Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:6.10.6 & 8.0.10-rc OS:Any
Assigned to: CPU Architecture:Any
Tags: .net, C#, core, EF, entity framework, NotImplementedException

[10 Apr 2018 11:13] James Czerwik
Description:
PM> Scaffold-DbContext "server=*******;port=3306;user=******;password=******;database=*****" MySql.Data.EntityFrameworkCore -OutputDir ***** -f
System.NotImplementedException: The method or operation is not implemented.
   at MySql.Data.EntityFrameworkCore.Scaffolding.Internal.MySQLDatabaseModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ModelScaffolder.Generate(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String projectPath, String outputPath, String rootNamespace, String contextName, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.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)
The method or operation is not implemented.

This is what I'm presented with when attempting to scaffold an existing database with EFCore and MySQL's EFCore libraries. This happens on both the latest stable (6.10.6) and latest pre-release (8.0.10-rc) versions.

Source code contains these two methods that don't have implementations:-

    public DatabaseModel Create(string connectionString, IEnumerable<string> tables, IEnumerable<string> schemas)
    {
      throw new NotImplementedException();
    }

    public DatabaseModel Create(DbConnection connection, IEnumerable<string> tables, IEnumerable<string> schemas)
    {
      throw new NotImplementedException();
    }

How to repeat:
(Assuming setup instructions have been followed from https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework-core.html. Visual Studio 2017 Community Edition was used)

1. Create new .Net Core Console App in Visual Studio
2. Install relevant packages from NuGet
3. Attempt to scaffold database in Package Manager Console using 'Scaffold-DbContext' command

Steps to verify source code is missing from installed package:
1. Install NuGet Package
2. Using JetBrains dotPeek program OR Resharper's Assembly Explorer, open package/assembly
3. Navigate to MySql.Data.EntityFrameworkCore.Scaffolding.Internal namespace
4. Navigate to MySQLDatabaseModelFactory class
5. Scroll to bottom of class to see the two functions causing the issue

Suggested fix:
Implement the functions required to scaffold the database
[10 Apr 2018 11:14] James Czerwik
Minor change to title
[20 Apr 2018 6:17] Chiranjeevi Battula
Hello James Czerwik,

Thank you for the bug report.
Verified based on internal discussion with dev's.

Thanks,
Chiranjeevi.
[30 Jul 2018 17:09] Arturo Mendez
Is there any fix for this? is there a workaround? Thanks!
[6 Aug 2018 17:32] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET 6.10.8 and 8.0.13 releases, and here's the changelog entry:

The implementation of some methods required to scaffold an existing
database were incomplete.

Thank you for the bug report.
[22 Aug 2018 13:25] Robin G
After installing MySQL Connector/NET 6.10.8 I still get the same error when using the Scaffold-DbContext command.
The issue is still not resolved in the newest version of MySQL Connector/NET 6.10.8.
Using NuGet packages in a project targeting .NET Core 2.0 framework:
- Microsoft.EntityFrameworkCore 2.1.2
- MySql.Data.EntityFrameworkCore.Design 8.0.12
- Microsoft.EntityFrameworkCore.Tools 2.1.2