.net Core使用EFCore连接数据库
一、SQL Service
1.创建实体类
public class Student
{
public int Id { get; set; }
[Required]
[Display(Name ="名:")]
public string FirstName{ get; set; }
[Required]
[Display(Name ="姓:")]
public string LastName { get; set; }
[Display(Name ="出生日期:")]
public DateTime BirthDate { get; set; }
[Display(Name ="性别:")]
public Gender Gender { get; set; }
}
2.创建DBContext.cs
public class DataContext:DbContext
{
public DataContext(DbContextOptions<DataContext> options):base(options)
{
} public DbSet<Student> Students { get; set; }
}
3.打开appsetting.json,添加连接字符串(SqlServer)
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "server=服务器名;database=数据库名;uid=用户名;pwd=密码;"
}
}
4.打开Startup.cs
//依赖注入
private readonly IConfiguration Configuration;
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
//注册服务
services.AddDbContext<DataContext>(
options =>
{
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
}
);
}
开始迁移。。。。。
.net Core使用EFCore连接数据库的更多相关文章
- abp(net core)+easyui+efcore仓储系统——解决方案介绍(二)
abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) ABP框架 首先介绍一下abp框架,abp其 ...
- abp(net core)+easyui+efcore仓储系统——展现层实现增删改查之控制器(六)
abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...
- abp(net core)+easyui+efcore仓储系统——领域层创建实体(三)
abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...
- abp(net core)+easyui+efcore仓储系统——定义仓储并实现 (四)
abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...
- abp(net core)+easyui+efcore仓储系统——创建应用服务(五)
abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...
- abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之列表视图(七)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- 2019年7月16日 abp(net core)+easyui+efcore实现仓储管理系统——多语言(十)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十一)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十二)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
随机推荐
- redis数据操作篇
服务器端 服务器端的命令为redis-server 可以使⽤help查看帮助⽂档 redis-server --help 个人习惯 ps aux | grep redis 查看redis服务器进程su ...
- AE开发中实现Control中的各种图形工具的方法(转)
Controls中的工具基本可以分为两类: 第一类:点击工具图标或按钮后,当前axMapControl的工具即为所点击的工具命令. 前面有Controls 后面有tool的工具都可以用同一类的代码实现 ...
- leetcode-160周赛-5239-循环码排列
题目描述: 参考格雷编码: class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: res ...
- 遍历实例化swiper
var list = $('.p04-s2 li'); list.each(function (index) { new Swiper ($(this).find('.swiper-container ...
- QT之QCustomPlot(二)
怎么设置X,Y轴位置 Manages a single axis inside a QCustomPlot. Usually doesn't need to be instantiated exter ...
- Jquery轻量级插件--操作URL
调用: > "?action=view§ion=info&id=123&debug&testy[]=true&testy[]=false ...
- php开发面试题---vue面试题(vue.js的好处及作用)
php开发面试题---vue面试题(vue.js的好处及作用) 一.总结 一句话总结: 双向数据绑定:在做ajax的时候,更新实在是太方便了 用数据绑定的思想,vue可以简单写单个页面,也可以写一个大 ...
- java Logger 类
package org.rx.common; import org.slf4j.LoggerFactory; import java.util.Collections; import java.uti ...
- Vim用法AAAAA
.linux系统中如何进入退出vim编辑器,方法及区别 我们当然要保存并退出了,然后下一步了.这时,我们要按键盘左上角的"ESC",留意到了没有?左下角的插入状态不见了,如图. 然 ...
- Bootstrap-table 使用总结 转载https://www.cnblogs.com/laowangc/p/8875526.html
一.什么是Bootstrap-table? 在业务系统开发中,对表格记录的查询.分页.排序等处理是非常常见的,在Web开发中,可以采用很多功能强大的插件来满足要求,且能极大的提高开发效率,本随笔介绍这 ...