如何使用Entity Framework Core直观地设计我的数据库?

时间:2021-08-07 09:20:54

I am wondering myself, how I should design my database scheme (in terms of efficiency and visuality).

我想知道自己,我应该如何设计我的数据库方案(在效率和可视性方面)。

I am developing a ASP.NET Core application with Angular 2 and I am using Entity Framework Core ("Microsoft.EntityFrameworkCore": "1.0.0"), since its my favourite ORM. I definitely prefer the SQL Server 2012, but if there are better options for designing my scheme available for other database management systems, I could switch to something else like PostgreSQL.

我正在使用Angular 2开发一个ASP.NET Core应用程序,我正在使用Entity Framework Core(“Microsoft.EntityFrameworkCore”:“1.0.0”),因为它是我最喜欢的ORM。我绝对更喜欢SQL Server 2012,但如果有更好的选择来设计我的方案可用于其他数据库管理系统,我可以切换到其他类似PostgreSQL。

EntityFrameworkCore however doesn't support designing the DataContext (with all its POCO classes) with the EDMX designer anymore.

然而,EntityFrameworkCore不再支持使用EDMX设计器设计DataContext(及其所有POCO类)。

Can you give me any advice how I can design my database visually and automatically generate my POCO classes (and maybe also my TypeScript classes)?

您能否给我任何建议,我可以直观地设计我的数据库并自动生成我的POCO类(也可能是我的TypeScript类)?

Can you recommend me a good tool for designing my scheme? (At least more convenient than SQL Server Management Studio. I liked the EDMX designer)

你能为我推荐一个设计我的方案的好工具吗? (至少比SQL Server Management Studio更方便。我喜欢EDMX设计师)

2 个解决方案

#1


4  

If you prefer to start with the database, you can use whatever design tools you find most useful for whichever database platform you prefer to create the database, and then use EF commands to scaffold your model and context from the database. You can execute commands from the Package Manager Console just as with migrations in previous versions of EF:

如果您更喜欢从数据库开始,则可以使用您认为最适合您创建数据库的数据库平台的任何设计工具,然后使用EF命令从数据库中构建模型和上下文。您可以从包管理器控制台执行命令,就像以前版本的EF中的迁移一样:

Scaffold-DbContext "Server=yourServer;Database=yourDb;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

The official documentation covers reverse engineering a model from an existing database

官方文档包括从现有数据库逆向工程模型

#2


1  

You can scaffold DbContext with enities using dotnet ef dbcontext scaffold command from terminal (console). So you can design DB in whatever way you want and then run scaffold command and you'll get your generated DbContext and classes.

您可以使用来自终端(控制台)的dotnet ef dbcontext scaffold命令使用enities来构建DbContext。因此,您可以以任何您想要的方式设计DB,然后运行scaffold命令,您将获得生成的DbContext和类。

Here's documentation on command: https://docs.efproject.net/en/latest/miscellaneous/cli/dotnet.html#dotnet-ef-dbcontext-scaffold

这是关于命令的文档:https://docs.efproject.net/en/latest/miscellaneous/cli/dotnet.html#dotnet-ef-dbcontext-scaffold

#1


4  

If you prefer to start with the database, you can use whatever design tools you find most useful for whichever database platform you prefer to create the database, and then use EF commands to scaffold your model and context from the database. You can execute commands from the Package Manager Console just as with migrations in previous versions of EF:

如果您更喜欢从数据库开始,则可以使用您认为最适合您创建数据库的数据库平台的任何设计工具,然后使用EF命令从数据库中构建模型和上下文。您可以从包管理器控制台执行命令,就像以前版本的EF中的迁移一样:

Scaffold-DbContext "Server=yourServer;Database=yourDb;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

The official documentation covers reverse engineering a model from an existing database

官方文档包括从现有数据库逆向工程模型

#2


1  

You can scaffold DbContext with enities using dotnet ef dbcontext scaffold command from terminal (console). So you can design DB in whatever way you want and then run scaffold command and you'll get your generated DbContext and classes.

您可以使用来自终端(控制台)的dotnet ef dbcontext scaffold命令使用enities来构建DbContext。因此,您可以以任何您想要的方式设计DB,然后运行scaffold命令,您将获得生成的DbContext和类。

Here's documentation on command: https://docs.efproject.net/en/latest/miscellaneous/cli/dotnet.html#dotnet-ef-dbcontext-scaffold

这是关于命令的文档:https://docs.efproject.net/en/latest/miscellaneous/cli/dotnet.html#dotnet-ef-dbcontext-scaffold