efcore数据库自动生成
Posted 吴晓阳
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了efcore数据库自动生成相关的知识,希望对你有一定的参考价值。
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.ConfigureNLog("nlog.config"); loggerFactory.AddNLog(); app.UseRequestIPMiddleware(); InitializeNetCoreBBSDatabase(app.ApplicationServices); app.UseDeveloperExceptionPage(); app.UseStaticFiles(); app.UseAuthentication(); app.UseStatusCodePages(); app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", template: "{area:exists}/{controller}/{action}", defaults: new { action = "Index" }); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } private void InitializeNetCoreBBSDatabase(IServiceProvider serviceProvider) { using (var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope()) { var db = serviceScope.ServiceProvider.GetService<DataContext>(); db.Database.Migrate(); if (db.TopicNodes.Count() == 0) { db.TopicNodes.AddRange(GetTopicNodes()); db.SaveChanges(); } } }
以上是关于efcore数据库自动生成的主要内容,如果未能解决你的问题,请参考以下文章
2021-06-23 .NET高级班 63-ASP.NET Core EFCore数据库(CodeFirst的使用)