core版本使用ef连接数据库(一)
2024-10-08 13:10:46
sqlserver数据库:①Nuget: Microsoft.EntityFrameworkCore.SqlServer
ORACLE数据库:①Nuget: Oracle.EntityFrameworkCore
以oracle为列:
新建DataDBContext连接类
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; namespace WebApplication2
{
public class DataDBContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseOracle(@"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.10.113)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));Persist Security Info=True;User ID=zhzepp;Password=citms", b => b.UseOracleSQLCompatibility(""));
} public DbSet<ASSETSEntity> OrderInfos { get; set; }//实体 static public void test()
{
using (var db = new DataDBContext())
{
var count = db.OrderInfos.Where(x => x.ASSETSID != null).ToList(); }
}
}
}
实体类
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks; namespace WebApplication2
{
[Table("ASSETS")]
public class ASSETSEntity
{
/// <summary>
/// 主键
/// </summary>
[Key]
public string ASSETSID { get; set; }
/// <summary>
/// TAGS
/// </summary>
[Column("TAGS"), MaxLength()]
public string TAGS { get; set; }
}
}
在Startup.cs里面
最新文章
- Android带边框表格的实现
- VB类模块中属性的参数——VBA中Range对象的Value属性和Value2属性的一点区别
- windbg sos加载相关
- keepalived初探
- HTTP Post Request using Apache Commons
- Mysql 锁粒度
- ssma for oracle
- Android安卓安全审计mobiseclab
- FileReader和FileInputStream的区别
- C#基础 运算符
- (原创)列主元Gauss消去法的通用程序
- KNN算法基本实例
- springboot:Java模板引擎Thymeleaf介绍
- 面向对象编程其实很简单——Python 面向对象(初级篇)
- C++ code:低级编程
- Java--TestNG
- asp.net webapi 自托管插件式服务(转)
- Spring Boot 应用系列 1 -- Spring Boot 2 整合Spring Data JPA和Druid,双数据源
- MySQL3:存储过程和函数
- LG3781 [SDOI2017]切树游戏