Code First to Database First to Code First
I created a new Core 2 MVC Project with Individual User Accounts for user authentication. I added code under base.OnModelCreating(builder) to modify the tables and created and ran a migration. This created the tables in a new database. All is fine. I already had a database with about 70 tables, complete with IDs, relations and indexes. So I create an SQL script and ran on the database, in MS SMS, to create these tables. Once that was done, I went back to the project and create the Models for these tables using Database first. The models look fine. This also create a public partial class that inherits from DbContext. In this class are all the public virtual DbSet for each of the tables.
I also have a protected override void OnConfiguring and a protected override void OnModelCreating(ModelBuilder modelBuilder).
My question are:
Now that the models are created, can I erase the OnModelCreating code since I no longer need to use database first?
Can I also eliminate the OnConfiguring code, which contains the connection string, and instead hook it up with the public void ConfigureServices(IServiceCollection services) code in Startup.cs, which was created by the project template, which has the reference to the connection string in appsettings? If so, how?
上一篇: 如何使用命令标志在将来的共享库上设置断点
下一篇: 代码优先,数据库优先,代码优先