.net core 通过代码创建数据库表
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 通过代码创建数据库表的更多相关文章
- hibernate动态创建数据库表名几种方式
数据库中数据量很大, 但又不可以删除时同时又要优化程序检索数据时间. 答:方式有很多比如 创建数据库表分区,创建索引, 存储过程等; 我这里采用动态创建数据库表的方式. 完全可以在不创建表分区情况下实 ...
- django使用model创建数据库表使用的字段
Django通过model层不可以创建数据库,但可以创建数据库表,以下是创建表的字段以及表字段的参数.一.字段1.models.AutoField 自增列= int(11) 如果没有的话,默认会生成一 ...
- Sql Server——运用代码创建数据库及约束
在没有学习运用代码创建数据库.表和约束之前,我们只能用鼠标点击操作,这样看起来就不那么直观(高大上)了. 在写代码前要知道在哪里写和怎么运行: 点击新建查询,然后中间的白色空白地方就是写代码的地方了. ...
- SQLAlchemy通过models创建数据库表
原地址:http://blog.csdn.net/jmilk/article/details/53184903 定义数据模型 models SQLAlchemy 允许我们根据数据库的表结构来创建数据模 ...
- SpringBoot使用Hibernate,实现自动创建数据库表【博客数据库设计】
我们准备设计博客,那就要设计数据库. 我们可以使用Hibernate来自动生成数据库. 博客数据库的结构: 实体类: 博客 Blog 博客分类 Type 博客标签 Tag 博客评论 Comment 用 ...
- 使用PowerDesigner创建数据库表图文并茂版
使用PowerDesigner创建数据库表图文并茂版 使用PowerDesigner 建数据库表. 一直很忙,没有时间写东西.这次搞点会声会色的,嘿嘿 此技能为项目经理必备技能. 本次主角: 1.在w ...
- 基于CentOS的MySQL学习补充三--使用Shell批量创建数据库表
本文出处:http://blog.csdn.net/u012377333/article/details/47006087 接上篇介绍<基于CentOS的Mysql学习补充二--使用Shell创 ...
- 数据库(一)--通过django创建数据库表并填充数据
django是不能创建数据库的,只能够创建数据库表,因此,我们在连接数据库的时候要先建立一个数据库. 在models.py中 from django.db import models class Pu ...
- Python 创建数据库表
创建数据库表 如果数据库连接存在我们可以使用execute()方法来为数据库创建表,如下所示创建表EMPLOYEE: #!/usr/bin/python # -*- coding: UTF-8 -*- ...
随机推荐
- vue报错 [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's
[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent c ...
- hackme.inndy.tw的一些Writeup(5月30更新)
hackme.inndy.tw的一些Writeup(6月3日更新) 原文链接:http://www.cnblogs.com/WangAoBo/p/7706719.html 推荐一下https://ha ...
- 一次m2eclipse的安装大坑经历之http://m2eclipse.sonatype.org/sites/m2e
m2eclipse 插件的安装在<Maven 实战>这本书上是这么说的: ”由于Eclipse默认没有集成对Maven的支持,幸运的是由Maven之父Jason Van Zyl创立的Son ...
- K8s控制器
K8s控制器 POD分类 #自主式pod:退出后,不会被创建 #控制器管理的pod:在控制器的生命周期内,始终位置pod的副本数 控制器类型 ReplicationController和Replica ...
- 【资源分享】Gmod日志记录脚本
*----------------------------------------------[下载区]----------------------------------------------* ...
- zabbix4.2配置监控MySQL
1.在被监控主机安装好MySQL 相关步骤省略. 2.创建监控所需要的MySQL账户(MySQL服务器端) MariaDB [(none)]>grant usage on *.* to zabb ...
- (转)http 之session和cookie
http://www.cnblogs.com/xuxm2007/archive/2011/12/05/2276705.html Session简介 摘 要:虽然session机制在web应用程序中被采 ...
- HDU1069 Monkey and Banana(dp)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意:给定n种类型的长方体,每个类型长方体无数个,要求长方体叠放在一起,且上面的长方体接触面积要小于 ...
- java.util.UUID工具类
生成数据表的主键Id会用到此工具类 /** * <获取主鍵> * <获取32位UUID> * @return * @see [类.类#方法.类#成员] */ public st ...
- logits的用法和此类标注的作用,已经再最后一层加了映射了就不需要再加入了
logits的用法和此类标注的作用,已经再最后一层加了映射了就不需要再加入了 待办 PyTorch(tensorflow类似)的损失函数中,有一个(类)损失函数名字中带了with_logits. 而这 ...