zoukankan      html  css  js  c++  java
  • core版本使用ef连接数据库(一)

    参考

    参考代码

    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("11"));
            }
     
            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(2000)]
            public string TAGS { get; set; }
        }
    }

    在Startup.cs里面

  • 相关阅读:
    Loadrunner系列学习--Loadrunner架构(1)
    Loadrunner学习---脚本编写(1)
    loadrunner学习系列---脚本编写(2)
    LoadRunner学习---脚本编写(4)(比较重要)
    LoadRunner内部结构(1)
    pat 1142
    pat 1025
    pat 1140
    c/c++ 常用函数/方法
    pat 1136
  • 原文地址:https://www.cnblogs.com/macT/p/12050072.html
Copyright © 2011-2022 走看看