Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaffold table fails with "Sequence contains no matching element" #1188

Open
mkmita opened this issue Aug 10, 2024 · 5 comments
Open

Scaffold table fails with "Sequence contains no matching element" #1188

mkmita opened this issue Aug 10, 2024 · 5 comments

Comments

@mkmita
Copy link

mkmita commented Aug 10, 2024

Hello,

FirebirdSql.EntityFrameworkCore.Firebird 11.0.0
FirebirdSql.Data.FirebirdClient 10.3.1
Entity framework 8.0.4
firebird db 3.0

I run command:

dotnet ef dbcontext scaffold "User=SYSDBA;Password=***;Database=\tt\tt\tt\tt.fdb;DataSource=localhost;Port=3050;Dialect=3;Charset=UTF8;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;" FirebirdSql.EntityFrameworkCore.Firebird --output-dir Models --context TTDbContext --context-dir DataContext --force

it hangs for some time, but fails with error

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 FirebirdSql.EntityFrameworkCore.Firebird.Scaffolding.Internal.FbDatabaseModelFactory.GetIndexes(DbConnection connection, IReadOnlyList`1 tables, Func`2 tableFilter)
   at FirebirdSql.EntityFrameworkCore.Firebird.Scaffolding.Internal.FbDatabaseModelFactory.GetTables(DbConnection connection, Func`2 filter)
   at FirebirdSql.EntityFrameworkCore.Firebird.Scaffolding.Internal.FbDatabaseModelFactory.Create(DbConnection connection, DatabaseModelFactoryOptions options)
   at FirebirdSql.EntityFrameworkCore.Firebird.Scaffolding.Internal.FbDatabaseModelFactory.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, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   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
@cincuranet
Copy link
Member

Please provide (minimal) DDL for your database.

@mkmita
Copy link
Author

mkmita commented Aug 23, 2024

Please provide (minimal) DDL for your database.

I got empty db file which gives same error and which i can share with you. Maybe i can send you download link by email?

@cincuranet
Copy link
Member

You can put the link here.

@vstiebe
Copy link

vstiebe commented Oct 5, 2024

The GetIndexes is failing for expression indexes probably because there is no columns for it.
Tested on 10.0.0.

index.Columns.Add(table.Columns.Single(y => y.Name == column.Trim()));

DDL for testing:

/*
drop table DETAIL_TABLE;
drop table MASTER_TABLE;
drop domain DN_DESCRIPTION;
drop domain DN_KEY;
*/

create domain DN_KEY as integer;
create domain DN_DESCRIPTION as varchar(255);

create table MASTER_TABLE (
  ID_MASTER_TABLE DN_KEY not null,
  DATA_FIELD DN_DESCRIPTION
);

alter table MASTER_TABLE add constraint PK_MASTER_TABLE primary key (ID_MASTER_TABLE);
commit;

create table DETAIL_TABLE (
  ID_DETAIL_TABLE DN_KEY not null,
  ID_MASTER_TABLE DN_KEY,
  DETAIL_DATA_FIELD DN_DESCRIPTION
);

alter table DETAIL_TABLE add constraint PK_DETAIL_TABLE primary key (ID_DETAIL_TABLE);
alter table DETAIL_TABLE add constraint FK_DETAIL_MASTER foreign key (ID_MASTER_TABLE) references MASTER_TABLE (ID_MASTER_TABLE) on update cascade on delete cascade;
create index IDX_DETAIL_DATA on DETAIL_TABLE (DETAIL_DATA_FIELD);
create descending index IDX_DETAIL_DATA_DESC on DETAIL_TABLE (DETAIL_DATA_FIELD);
create unique index AK_DETAIL_TABLE on DETAIL_TABLE (DETAIL_DATA_FIELD);
create index IDX_DETAIL_EXP on DETAIL_TABLE computed by (upper (DETAIL_DATA_FIELD));
commit;

The command line I used:

dotnet ef dbcontext scaffold 'DataSource=localhost;Database=d:\test.fdb;User=sysdba;Password=masterkey;Port=3050;' FirebirdSql.EntityFrameworkCore.Firebird --project '.\Test\Test.csproj' --force --data-annotations

@mkmita
Copy link
Author

mkmita commented Oct 18, 2024

Hello guys,

-- "ADDRESS" definition

-- Drop table

-- DROP TABLE "ADDRESS";

CREATE TABLE "ADDRESS" (
	"ADDRESS" INTEGER NOT NULL,
	STREETNUMBER VARCHAR(40),
	CONSTRAINT INTEG_10 PRIMARY KEY ("ADDRESS")
);
CREATE UNIQUE INDEX IDX_ADDRESS_PK ON "ADDRESS" ("ADDRESS");
CREATE INDEX IDX_ADDRESS_FAILING_TEST ON "ADDRESS" ();

same command

dotnet ef dbcontext scaffold "User=SYSDBA;Password=***;Database=\tt\tt\tt\tt.fdb;DataSource=localhost;Port=3050;Dialect=3;Charset=UTF8;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;" FirebirdSql.EntityFrameworkCore.Firebird --output-dir Models --context TTDbContext --context-dir DataContext --force

error

Attempting to create database model...
An error occurred during scaffolding: Sequence contains no matching element
   at System.Linq.ThrowHelper.ThrowNoMatchException()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at EfScaffoldingDebugger.GetIndexes(DbConnection connection, IReadOnlyList`1 tables) in EfCoreDebug\src\EfCoreScaffolderDebugger.cs:line 209
   at EfScaffoldingDebugger.GetTablesManually(FbConnection connection) in EfCoreDebug\src\EfCoreScaffolderDebugger.cs:line 114
   at EfScaffoldingDebugger.GetDatabaseModelManually() in EfCoreDebug\src\EfCoreScaffolderDebugger.cs:line 74
   at EfScaffoldingDebugger.DebugScaffolding() in EfCoreDebug\src\EfCoreScaffolderDebugger.cs:line 40
Press any key to exit...

Best Regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants