.net core 通过代码创建数据库表
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了.net core 通过代码创建数据库表,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2635字,纯文字阅读大概需要4分钟。
内容图文
1.API
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using HYS.BT.AcitivityAppSrv; using HYS.BT.AcitivityDomains; using HYS.BT.Utils; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json.Serialization; using Swashbuckle.AspNetCore.Swagger; namespace HYS.BT.AcitivityApi { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; AppSetting.SetAppSetting(Configuration.GetSection("ConfigurationInfo")); } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); }); ; // services.AddMvcCore().AddApiExplorer(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "血检消息活动API", Version = "v1", Contact = new Contact() { Name = "好医生 John Lau", Email = "343626385@qq.com" } }); var basepath = System.AppContext.BaseDirectory; string[] arr = new string[] { "HYS.BT.AcitivityAppSrv.xml", "HYS.BT.AcitivityApi.xml" }; foreach (var item in arr) { var xmlpath = Path.Combine(basepath, item); c.IncludeXmlComments(xmlpath); } }); string[] urls = Configuration.GetSection("AllowedCors").Value.Split(","); services.AddCors(c => c.AddPolicy("AllowAllOrigin", bulid => { bulid.WithOrigins(urls).AllowAnyMethod().AllowAnyHeader().AllowCredentials(); })); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseCors("AllowAllOrigin"); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "血检消息活动API V1"); //c.ShowRequestHeaders(); }); //app.UseMvc(routes => //{ // routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); //}); app.UseMvc(); } } }
内容总结
以上是互联网集市为您收集整理的.net core 通过代码创建数据库表全部内容,希望文章能够帮你解决.net core 通过代码创建数据库表所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。