[英]dotnet ef dbcontext scaffold command --data-annotations or -d command line parameter doesn't seem to work
I have a simple database with one table, that has various properties.我有一个带有一个表的简单数据库,它具有各种属性。
I am using the latest .NET core 6 with the latest EF (6.0.4)我正在使用最新的 .NET core 6 和最新的 EF (6.0.4)
I wanted to scaffold my database so it generates models, so I run the command:我想搭建我的数据库以便它生成模型,所以我运行以下命令:
dotnet ef dbcontext scaffold "Server=MyServerName;Database=MyDBName;User Id=sa;Password=abc123;"
Microsoft.EntityFrameworkCore.SqlServer -o Model --no-pluralize -d -f
the -d command is supposed to use data annotations rather than fluent annotation, however it does not. -d 命令应该使用数据注释而不是流利的注释,但它没有。 I end up with a
MyTable
class, with the properties listed plainly, eg public int MyTableId; public string MyTableProperty;....
我最终得到了一个
MyTable
类,其中的属性一目了然,例如public int MyTableId; public string MyTableProperty;....
public int MyTableId; public string MyTableProperty;....
and then in my MyDBNameContext
class OnModelCreating
method, several pages of stuff like this: public int MyTableId; public string MyTableProperty;....
然后在我的MyDBNameContext
类OnModelCreating
方法中,有几页这样的东西:
modelBuilder.Entity<MyTable>(entity =>
{
entity.HasIndex(e => e.SomeColumn, "idx_somecolumn");
entity.Property(e => e.firstcolumn)
.HasColumnType("decimal(8, 1)")
.HasColumnName("FirstColumn");
...
This is pretty hideous.这是相当可怕的。 The help states this:
帮助说明了这一点:
-d|--data-annotations Use attributes to configure the model (where possible).
-d|--data-annotations 使用属性来配置模型(如果可能)。 If omitted, only the fluent API is used.
如果省略,则仅使用 fluent API。
I could painstakingly go through manually and add the annotations but then if I regenerate in the future due to changes, then it will undo my work.我可以煞费苦心地手动完成并添加注释,但是如果我将来由于更改而重新生成,那么它将撤消我的工作。
Is there a reason why the data annotations attribute is not working?数据注释属性不起作用是有原因的吗?
I can't delete my question so I'll just post the answer here...我无法删除我的问题,所以我将在此处发布答案...
It's a bug!这是一个错误!
-d
is not working, but --data-annotations
is working. -d
不工作,但--data-annotations
工作。
https://github.com/dotnet/efcore/issues/26687 https://github.com/dotnet/efcore/issues/26687
You can use this:你可以使用这个:
dotnet ef dbcontext scaffold
"Server=MyServerName;Database=MyDBName;User Id=sa;Password=abc123;"
Microsoft.EntityFrameworkCore.SqlServer -o Model --no-pluralize --data-annotations -f
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.