0.结构:

1.API

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore;
  7. using Microsoft.AspNetCore.Hosting;
  8. using Microsoft.Extensions.Configuration;
  9. using Microsoft.Extensions.Logging;
  10.  
  11. namespace LJS.Api
  12. {
  13. public class Program
  14. {
  15. public static void Main(string[] args)
  16. {
  17. CreateWebHostBuilder(args).Build().Run();
  18. }
  19.  
  20. public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
  21. WebHost.CreateDefaultBuilder(args).UseIIS().UseStartup<Startup>();
  22. }
  23. }
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using LJS.AppSrv;
  7. using LJS.Domains;
  8. using LJS.Utils;
  9. using Microsoft.AspNetCore.Builder;
  10. using Microsoft.AspNetCore.Hosting;
  11. using Microsoft.AspNetCore.HttpsPolicy;
  12. using Microsoft.AspNetCore.Mvc;
  13. using Microsoft.Extensions.Configuration;
  14. using Microsoft.Extensions.DependencyInjection;
  15. using Microsoft.Extensions.Logging;
  16. using Microsoft.Extensions.Options;
  17. using Newtonsoft.Json.Serialization;
  18. using Swashbuckle.AspNetCore.Swagger;
  19.  
  20. namespace LJS.Api
  21. {
  22. public class Startup
  23. {
  24. public Startup(IConfiguration configuration)
  25. {
  26. Configuration = configuration;
  27. AppSetting.SetAppSetting(Configuration.GetSection("ConfigurationInfo"));
  28. }
  29.  
  30. public IConfiguration Configuration { get; }
  31.  
  32. // This method gets called by the runtime. Use this method to add services to the container.
  33. public void ConfigureServices(IServiceCollection services)
  34. {
  35. //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
  36. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); }); ;
  37. // services.AddMvcCore().AddApiExplorer();
  38. services.AddSwaggerGen(c =>
  39. {
  40. c.SwaggerDoc("v1", new Info { Title = "信息API", Version = "v1", Contact = new Contact() { Name = "作者", Email = "电子邮箱" } });
  41.  
  42. var basepath = System.AppContext.BaseDirectory;
  43. string[] arr = new string[] { "LJS.AppSrv.xml", "LJS.Api.xml" };
  44.  
  45. foreach (var item in arr)
  46. {
  47. var xmlpath = Path.Combine(basepath, item);
  48. c.IncludeXmlComments(xmlpath);
  49. }
  50. });
  51.  
  52. string[] urls = Configuration.GetSection("AllowedCors").Value.Split(",");
  53. services.AddCors(c => c.AddPolicy("AllowAllOrigin", bulid =>
  54. {
  55. bulid.WithOrigins(urls).AllowAnyMethod().AllowAnyHeader().AllowCredentials();
  56. }));
  57. }
  58.  
  59. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  60. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  61. {
  62. if (env.IsDevelopment())
  63. {
  64. app.UseDeveloperExceptionPage();
  65. }
  66. else
  67. {
  68. app.UseHsts();
  69. }
  70.  
  71. app.UseHttpsRedirection();
  72.  
  73. // Enable middleware to serve generated Swagger as a JSON endpoint.
  74.  
  75. app.UseCors("AllowAllOrigin");
  76.  
  77. // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
  78. // specifying the Swagger JSON endpoint.
  79. app.UseSwagger();
  80.  
  81. app.UseSwaggerUI(c =>
  82. {
  83. c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1");
  84. //c.ShowRequestHeaders();
  85. });
  86. //app.UseMvc(routes =>
  87. //{
  88. // routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
  89. //});
  90. app.UseMvc();
  91. }
  92. }
  93. }

2.设置API为启动项目

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

4.运行

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

Update-Database "PartXXMigs" -Context "DbXXContext"

5.api - launchSettings.json

  1. {
  2. "$schema": "http://json.schemastore.org/launchsettings.json",
  3. "iisSettings": {
  4. "windowsAuthentication": false,
  5. "anonymousAuthentication": true,
  6. "iisExpress": {
  7. "applicationUrl": "http://localhost:62806",
  8. "sslPort": 0
  9. }
  10. },
  11. "profiles": {
  12. "IIS Express": {
  13. "commandName": "IISExpress",
  14. "launchBrowser": true,
  15. "launchUrl": "swagger",
  16. "environmentVariables": {
  17. "ASPNETCORE_ENVIRONMENT": "Development"
  18. }
  19. },
  20. "LJS.Api": {
  21. "commandName": "Project",
  22. "launchBrowser": true,
  23. "launchUrl": "swagger",
  24. "applicationUrl": "http://localhost:5000",
  25. "environmentVariables": {
  26. "ASPNETCORE_ENVIRONMENT": "Development"
  27. }
  28. }
  29. }
  30. }

.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. navicat连接mysql8.0+版本报错2059

    ERROR 2059 : Authentication plugin 'caching_sha2_password' cannot be loaded 问题: 连接Docker启动的mysql出现:E ...

  2. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy

    //因为可以反转n次 所以可以得到任何可以构成的序列 #include<iostream> #include<string> #include<vector> us ...

  3. ubuntu---【nvcc --version】显示错误,提示 sudo apt-get install nvidia-cuda-toolkit

    重装了一下cuda,然后发现nvcc命令不存在了,终端提示使用 : sudo apt-get install nvidia-cuda-toolkit 来使用nvcc. 注意不要使用这种方式安装.系统认 ...

  4. wamp 增加mongodb拓展 安装

    安装环境: windows 7 64bit php 5.5.12 确认环境参数: 1.在phpinfo() 中查看compiler 2.在phpinfo() 中查看thread safety,线程是否 ...

  5. Laravel 中使用 Laravel-Excel 美化

    <?php use Maatwebsite\Excel\Classes\LaravelExcelWorksheet; use Maatwebsite\Excel\Exceptions\Larav ...

  6. Java-重载和重写区别剖析

    重载(Overload)和重写(Override)是任何一门面向对象的语言都会具有的两个特性,自然,Java语言中也具有此两种特性.但是,对于Java新手,或者没有面向对象语言经验的开发者而言,这会是 ...

  7. H5Plus 入门学习-Dcloud H5+ API调用实例

    使用API Reference完整简单的操作,更多操作查看官方文档. 最后提供项目的下载地址[下载][一款移动APP演示]

  8. Unity 读取Json常用的两种方式

    使用的是Litjson 1.读取本地Json public void ReadJson() { StreamReader streamReader = new StreamReader(Applica ...

  9. codeforces 1285D. Dr. Evil Underscores(字典树)

    链接:https://codeforces.com/problemset/problem/1285/D 题意:给n个数a1,a2,a3.....an,找到一个数X,使得X 异或所有的ai ,得到的ma ...

  10. RPA项目所遇知识点

    1艺赛旗 RPA 技术分享常见问题汇总贴 2python标准库之glob介绍 3RPA基础 4RPA答疑 5python3 遍历windows下 所有句柄及窗口名称 import win32gui h ...