0.结构:

1.API

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; namespace LJS.Api
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
} public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args).UseIIS().UseStartup<Startup>();
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using LJS.AppSrv;
using LJS.Domains;
using LJS.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 LJS.Api
{
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 = "作者", Email = "电子邮箱" } }); var basepath = System.AppContext.BaseDirectory;
string[] arr = new string[] { "LJS.AppSrv.xml", "LJS.Api.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();
}
}
}

2.设置API为启动项目

3.在VS打开 程序包管理控制台,选择DOMAINS项目

4.运行

Add-Migration "PartXXMigs" -OutputDir "Migrations" -Context "DbXXContext"

Update-Database "PartXXMigs" -Context "DbXXContext"

5.api - launchSettings.json

{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:62806",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"LJS.Api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

.net core 通过代码创建数据库表的更多相关文章

  1. hibernate动态创建数据库表名几种方式

    数据库中数据量很大, 但又不可以删除时同时又要优化程序检索数据时间. 答:方式有很多比如 创建数据库表分区,创建索引, 存储过程等; 我这里采用动态创建数据库表的方式. 完全可以在不创建表分区情况下实 ...

  2. django使用model创建数据库表使用的字段

    Django通过model层不可以创建数据库,但可以创建数据库表,以下是创建表的字段以及表字段的参数.一.字段1.models.AutoField 自增列= int(11) 如果没有的话,默认会生成一 ...

  3. Sql Server——运用代码创建数据库及约束

    在没有学习运用代码创建数据库.表和约束之前,我们只能用鼠标点击操作,这样看起来就不那么直观(高大上)了. 在写代码前要知道在哪里写和怎么运行: 点击新建查询,然后中间的白色空白地方就是写代码的地方了. ...

  4. SQLAlchemy通过models创建数据库表

    原地址:http://blog.csdn.net/jmilk/article/details/53184903 定义数据模型 models SQLAlchemy 允许我们根据数据库的表结构来创建数据模 ...

  5. SpringBoot使用Hibernate,实现自动创建数据库表【博客数据库设计】

    我们准备设计博客,那就要设计数据库. 我们可以使用Hibernate来自动生成数据库. 博客数据库的结构: 实体类: 博客 Blog 博客分类 Type 博客标签 Tag 博客评论 Comment 用 ...

  6. 使用PowerDesigner创建数据库表图文并茂版

    使用PowerDesigner创建数据库表图文并茂版 使用PowerDesigner 建数据库表. 一直很忙,没有时间写东西.这次搞点会声会色的,嘿嘿 此技能为项目经理必备技能. 本次主角: 1.在w ...

  7. 基于CentOS的MySQL学习补充三--使用Shell批量创建数据库表

    本文出处:http://blog.csdn.net/u012377333/article/details/47006087 接上篇介绍<基于CentOS的Mysql学习补充二--使用Shell创 ...

  8. 数据库(一)--通过django创建数据库表并填充数据

    django是不能创建数据库的,只能够创建数据库表,因此,我们在连接数据库的时候要先建立一个数据库. 在models.py中 from django.db import models class Pu ...

  9. Python 创建数据库表

    创建数据库表 如果数据库连接存在我们可以使用execute()方法来为数据库创建表,如下所示创建表EMPLOYEE: #!/usr/bin/python # -*- coding: UTF-8 -*- ...

随机推荐

  1. 【转】idea远程调试

    适用于web服务,thrift服务 对于分布式系统的调试不知道大家有什么好的方法.对于我来说,在知道远程调试这个方法之前就是在代码中打各种log,然后重新部署,上线,调试,这样比较费时.今天咱们来了解 ...

  2. MySQL启动和停止

    MySQL视为大仓库,关闭的时候有权限有身份都无法进入使用的时候要保持启用状态 方式一: 计算机游击找到“管理”打开 左侧栏目中找到“服务和应用程序”打开 打开服务 找到MySQL...,右击.... ...

  3. pikaqiu练习平台(SQL注入 )

    sql注入漏洞 (危害是最大得) Sql注入 数据库注入漏洞,主要是开发人员在构建代码时,没有对输入边界进行安全考虑,导致攻击者可以通过合法的输入点提交一些精心构造的语句,从而欺骗后台数据库对其进行执 ...

  4. EF中的查询方法

    1.Linq to Entity(L2E)查询 默认返回IQueryable类型 2.原生SQL查询和操作 ①DbSet.SqlQuery()和Database.SqlQuery() 返回DbSqlQ ...

  5. Linux oracle中文乱码的问题解决

    乱码问题的根源是字符集的修改 1.查看linux的默认语言 2.查看客户端的语言编码设置 配置文件中的配置: cat  ~/.bash_profile 注意修改配置信息: export PATHexp ...

  6. 通过恢复目录(Catalogue)进行PDB级别的PITR恢复

    数据库版本:Oracle 12.2.0.1 本篇为<执行PDB的PITR恢复失败的说明 (文档 ID 2435452.1)>的证明篇,通过当前控制文件,无法在PDB级别进行PITR(Poi ...

  7. Centos7搭建Apache2.4

    我不多说废话了,相信在座的都应该明白怎么安装Apache2.4,我这才用yum源安装的,我个人认为这样安装的话,可以节省一些时间,有的网络不是很好,要等一段时间. 配置与Apache2.2的版本有点变 ...

  8. 虚拟机linux系统网络连接配置问题总结

    1.虚拟机与CentOS的安装与配置参考本人博客:https://www.cnblogs.com/ClikeL/p/11743520.html 2.测试网络连接 ping www.baidu.com ...

  9. asp.net使用wsdl文件调用接口,以及调用SSL接口报错“根据验证过程 远程证书无效”的处理

    1.调用wsdl接口,首先需要将wsdl文件转换为cs文件: 进入VS 开发人员命令提示行,输入如下命令: c:/Program Files/Microsoft Visual Studio 8/VC& ...

  10. vs2015制作一个超级简单的MVC项目

    使用vs2015制作一个超级简单的MVC项目   本文链接:https://blog.csdn.net/qq_40919762/article/details/100705314 直奔主题一,创建一个 ...