'Sequence contains no matching element' scaffolding database tables
See original GitHub issueSteps to reproduce
dotnet ef dbcontext scaffold "connect string" "Pomelo.EntityFrameworkCore.MySql" --verbose
The issue
Throws an exception after not finding design-time services.
Using project 'd:\Client\olab\devel\repos\OLab4\OLab4-api\Service\OLabWebAPI.csproj'.
Using startup project 'd:\Client\olab\devel\repos\OLab4\OLab4-api\Service\OLabWebAPI.csproj'.
Writing 'd:\Client\olab\devel\repos\OLab4\OLab4-api\Service\obj\OLabWebAPI.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\corey\AppData\Local\Temp\tmp3401.tmp /verbosity:quiet /nologo d:\Client\olab\devel\repos\OLab4\OLab4-api\Service\OLabWebAPI.csproj
Writing 'd:\Client\olab\devel\repos\OLab4\OLab4-api\Service\obj\OLabWebAPI.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\corey\AppData\Local\Temp\tmp35D7.tmp /verbosity:quiet /nologo d:\Client\olab\devel\repos\OLab4\OLab4-api\Service\OLabWebAPI.csproj
Build started...
dotnet build d:\Client\olab\devel\repos\OLab4\OLab4-api\Service\OLabWebAPI.csproj /verbosity:quiet /nologo
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.93
Build succeeded.
dotnet exec --depsfile d:\Client\olab\devel\repos\OLab4\OLab4-api\Service\bin\Debug\netcoreapp3.1\OLabWebAPI.deps.json --additionalprobingpath C:\Users\corey\.nuget\packages --runtimeconfig d:\Client\olab\devel\repos\OLab4\OLab4-api\Service\bin\Debug\netcoreapp3.1\OLabWebAPI.runtimeconfig.json C:\Users\corey\.dotnet\tools\.store\dotnet-ef\5.0.0\dotnet-ef\5.0.0\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll dbcontext scaffold server=diskstation.local;uid=entrada_dev;pwd=b012db9d53B!;database=dev_olab Pomelo.EntityFrameworkCore.MySql --assembly d:\Client\olab\devel\repos\OLab4\OLab4-api\Service\bin\Debug\netcoreapp3.1\OLabWebAPI.dll --startup-assembly d:\Client\olab\devel\repos\OLab4\OLab4-api\Service\bin\Debug\netcoreapp3.1\OLabWebAPI.dll --project-dir d:\Client\olab\devel\repos\OLab4\OLab4-api\Service\ --language C# --working-dir d:\Client\olab\devel\repos\OLab4\OLab4-api\Service --verbose --root-namespace OLabWebAPI
Using assembly 'OLabWebAPI'.
Using startup assembly 'OLabWebAPI'.
Using application base 'd:\Client\olab\devel\repos\OLab4\OLab4-api\Service\bin\Debug\netcoreapp3.1'.
Using working directory 'd:\Client\olab\devel\repos\OLab4\OLab4-api\Service'.
Using root namespace 'OLabWebAPI'.
Using project directory 'd:\Client\olab\devel\repos\OLab4\OLab4-api\Service\'.
Remaining arguments: .
Finding design-time services for provider 'Pomelo.EntityFrameworkCore.MySql'...
Using design-time services from provider 'Pomelo.EntityFrameworkCore.MySql'.
Finding design-time services referenced by assembly 'OLabWebAPI'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'OLabWebAPI'...
No design-time services were found.
System.InvalidOperationException: Sequence contains no matching element
at System.Linq.ThrowHelper.ThrowNoMatchException()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
at Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal.MySqlDatabaseModelFactory.GetConstraints(DbConnection connection, IReadOnlyList`1 tables)
at Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal.MySqlDatabaseModelFactory.GetTables(DbConnection connection, Func`3 filter)
at Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal.MySqlDatabaseModelFactory.Create(DbConnection connection, DatabaseModelFactoryOptions options)
at Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal.MySqlDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, 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 outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>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)
Sequence contains no matching element
Further technical details
MySQL version: 10.3.29 MariaDB Operating system: Windows 10 Pomelo.EntityFrameworkCore.MySql version: 3.2.7
Other details about my project setup:
Solution made up of main ‘Services’ project, with a dependancy to a ‘Data’ classlib project that contains the DBContext.
Ran scaffolding in main .EXE project source directory (OLabWebAPI.csproj). DBContext is in dependant project called ‘Data’. Tried running the scaffolding in Data.csproj directory and same result.
I tried adding the following to the project that has my DBContext, to no avail:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
// this is only used for scaffolding
public class DesignTimeOLabDBContext : IDesignTimeDbContextFactory<OLabDBContext>
{
public OLabDBContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<OLabDBContext>();
// pass your design time connection string here
optionsBuilder.UseMySql("connect string");
return new OLabDBContext(optionsBuilder.Options);
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:10
Top Results From Across the Web
Sequence contains no matching element scaffolding visual ...
The model were generated successifully from the database but adding a controller for the specified model using scaffolding returns error.
Read more >Sequence contains no matching element when scaffolding
Run the scaffold command. dotnet ef dbcontext scaffold "User=SYSDBA;Password=.....;Database=/var/lib/firebird/2.5/data ...
Read more >Sequence Contains No Matching Element: Solved
Sequence contains no matching element because your search criterion is wrong. Read this article, and we'll teach you how to fix the exception...
Read more >Solved: Re: Error: Sequence contains no matching element
Hi, I got this same error today and I tried refreshing table by table in the model - so identified which table was...
Read more >Scaffolding Or Reverse Engineering - Database
ODP.NET EF Core supports scaffolding the following tables and views: Relational tables and views. Materialized views. By convention, ODP.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@RotateAt60MPH The
No design-time services were found.
message is just an informational message that your project did not explicitly define any design-time services. Getting this message with the--verbose
flag is normal, as most projects do not explicitly implement their own design-time services. So the message is completely unrelated to your issue.However, to easily debug the issue (or even implement a workaround later), you can actually just add a custom design time service. Add the
CustomMySqlDesignTimeServices
andCustomMySqlDatabaseModelFactory
classes from the following code to your project:Program.cs
The
CustomMySqlDatabaseModelFactory.GetConstraints()
method is the one that the original 3.2.7 implementation uses (with theDebugger.Launch();
line added).Just scaffold again and the JIT debugger should pop up. You can then just debug the method (or replace
tables.Single()
withtables.SingleOrDefault()
).Probably related to PR https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/pull/1364 that hasn’t been backported to 3.2-maint branch yet.