[英]How do I Scaffold tables with EF.Core Database First containing special characters $
I have the following table in our SQL Server:我的 SQL Server 中有下表:
[prod].[dbo].[My Company$Customer]
I want to Scaffold this table with:我想用以下内容来搭建这张桌子:
Scaffold-DbContext "Server=SQLPROD;Database=prod;Trusted_Connection=True;integrated security=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -table "dbo.My Company$Customer"
But it will always give me the following error:但它总是会给我以下错误:
Unable to find a table in the database matching the selected table
If I omit the -table switch everything works fine, but I get ALL tables, which are A LOT and I don't need them.如果我省略 -table 开关,一切正常,但我得到所有表,这些表很多,我不需要它们。 So how can I use the -table switch correctly?
那么如何正确使用 -table 开关呢? I am using ef.core 2.2.1
我正在使用 ef.core 2.2.1
In SQL Server, if you have special characters in your table names (eg spaces or anything that isn't a letter or number) then you need to surround the object name with square brackets.在 SQL Server 中,如果您的表名中有特殊字符(例如空格或任何不是字母或数字的东西),那么您需要用方括号将对象名括起来。 So your command line would become something like this:
所以你的命令行会变成这样:
Scaffold-DbContext "<connection-string>"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
-table "[dbo].[My Company$Customer]"
You strictly don't need the square brackets around the schema ( dbo
) but there's no harm in including them there too.您绝对不需要模式(
dbo
)周围的方括号,但将它们包含在那里也没有坏处。
使用 EF Core 3.1 我不得不转义 $ 字符。
Scaffold-DbContext "Server=myServer;Database=myDB;User Id=sa;Password=xyz;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -table "[dbo].[My Company`$Product]"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.