Home > Back-end >  How do I scaffold a table with space in it's name in ASP Net. Core?
How do I scaffold a table with space in it's name in ASP Net. Core?

Time:08-24

I wanna turn my table from already existing database into model using Scaffold-DbContext but the table in question have space in it's name. Let's call this table Supieriors types. I've tried doing in like this:

Scaffold-DbContext "Server=CRM_server;Database=CRMDB;User ID=CRM_access;Password=" Microsoft.EntityFrameworkCore.SqlServer
-OutputDir Models -Tables Supieriors types -Force

and

Scaffold-DbContext "Server=CRM_server;Database=CRMDB;User ID=CRM_access;Password=" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables Supieriors_types -Force

After second attempt I didn't get any error massage, just Build failed. I'm using -Force flag since I already have 2 other models scaffolded. Also I would like to avoid renaming the table to remove space.

CodePudding user response:

Did you try putting the table name in the string? Example: Scaffold-DbContext "Server=CRM_server;Database=CRMDB;User ID=CRM_access;Password=" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -table "[dbo].[Supieriors types]"

CodePudding user response:

-Tables Supieriors types

Is just not registering correct with the command line parameters, it doesn even reach the Scaffold-DbContext command. To make sure the command line knows it's one word, use quotes:

-Tables "Supieriors types"

That said... you will encounter problems everywhere with those table names. You can either find workaround after workaround in every tool you use, or rename the table to something normal once and for all.

  • Related