Efcore: Scaffold a subset of tables - silently ignores / skips tables that cannot be found

Created on 23 Dec 2015  路  9Comments  路  Source: dotnet/efcore

I have an existing database that I'd like to scaffold a DbContext from, but only for a subset of the tables in this database.

I tried:

dnx ef dbcontext scaffold "connstring" EntityFramework.MicrosoftSqlServer --outputDir Models --table dbo.table1 --table dbo.table2

UPDATE: This doesn't work - it seemed to only scaffold the second table.

This does work, but the table names are case sensitive, and if you get the casing wrong, then it seems to silently skip the scaffolding of that table.

I think it should output a warning to say that a table was skipped for some reason.

providers-beware type-bug

Most helpful comment

If anyone got the below error,

_Scaffold-DbContext : Cannot bind parameter because parameter 'Tables' is specified more than once. To provide multiple values to parameters that can accept multiple values, use
the array syntax. For example, "-parameter value1,value2,value3".At line:1 char:335_

Then try the following format,

dnx ef dbcontext scaffold "connstring" EntityFramework.MicrosoftSqlServer --outputDir Models -t dbo.table1, dbo.table2

then try the following command

All 9 comments

Have you tried "-t" ie no double hyphens?

Oh yikes - tried using -t dbo.table1 -t dbo.table2 and this time it worked.. which led me to re-look at the issue. --table dbo.table1 --table dbo.table2 also worked! So how come it didn't work when I first tried? Well.. the table names are case sensitive, and if you get the casing wrong it appears to be silently ignored when scaffolding - and this made me think that it was only ever doing one table but really it was silently ignoring the one with incorrect casing.

I think if it doesn't like a table it should probably output a warning of some kind to say that it skipped scaffolding for a table because it couldn't find it! :)

Thanks for prompting me to relook at this and figure it out!

I think it should not be case sensitive at all!

I think it should not be case sensitive at all

Agreed, as I don't think any of the major relational databases let table names only differ by case.

I think if it doesn't like a table it should probably output a warning of some kind to say that it skipped scaffolding for a table because it couldn't find it

Also agreed, since you explicitly asked for that table to be included

@lajones we should warn if the table is not found. Case sensitivity should be up to the provider (and ours should not be case sensitive).

Note: case-sensitivity was fixed by @ErikEJ with bfc8da1 (Thanks Erik).

Note: each provider interprets the --schema and --table selections according to its own rules (e.g. the SQL Server provider allows you to pass [schema].[table] as well as schema.table) - and so will also need to be responsible for the functionality that interprets whether those selections have been satisfied.

Fix checked in with PR#4252. Commit 50c51e7.

If anyone got the below error,

_Scaffold-DbContext : Cannot bind parameter because parameter 'Tables' is specified more than once. To provide multiple values to parameters that can accept multiple values, use
the array syntax. For example, "-parameter value1,value2,value3".At line:1 char:335_

Then try the following format,

dnx ef dbcontext scaffold "connstring" EntityFramework.MicrosoftSqlServer --outputDir Models -t dbo.table1, dbo.table2

then try the following command

Was this page helpful?
0 / 5 - 0 ratings