首页 > 数据库 >oracle EF core hello world

oracle EF core hello world

时间:2024-07-27 11:06:50浏览次数:11  
标签:core EF db var item num oracle using public

  1. 在oracle数据库里建一个表
    CREATE TABLE student (
        num int not null,
        name varchar2(200) not null,
        PRIMARY KEY(num)
     );
    
  2. 通过vs studio2022建一个"控制台应用"类型的项目.
  3. 通过vs studio上的nuget下载Oracle.EntityFrameworkCore,Microsoft.EntityFrameworkCore.Tools
  4. 使用EF core的代码如下:
    using Microsoft.EntityFrameworkCore;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    namespace d0001_efc1
    {
        class Program
        {
            public class StudentContext : DbContext
            {
                public DbSet<Student>? Students { get; set; }
    
    
                protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
                {
                    optionsBuilder.UseOracle(@"User Id=test_user;Password=123456;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=aaa)))");
                }
            }
            [Table("STUDENT")]
            public class Student
            {
                [Column("NUM")]
                [Key]
                public int num { get; set; }
                [Column("NAME")]
                public string? name { get; set; }
    
    
            static void Main(string[] args)
            {
                using (var db = new StudentContext())
                {
                    var student = new Student { num = 4, name = "张三" };
                    db.Students!.Add(student);
                    db.SaveChanges();
                }
    
                using (var db = new StudentContext())
                {
                    var blogs = db.Students;
                    foreach (var item in blogs!)
                    {
                        Console.WriteLine(item.name);
                            Console.WriteLine(item.num);
                            //Console.WriteLine(item.Url + " has rating " + item.Rating );
                        }
                }
                Console.ReadLine();
            }
        }
        }
    }
    
  5. 参考资料
    oracle EF core官方demo

标签:core,EF,db,var,item,num,oracle,using,public
From: https://www.cnblogs.com/zhouyang209117/p/18326741

相关文章

  • Codeforces Round 962 (Div. 3) 题解
    A.Legshttps://codeforces.com/contest/1996/problem/A翻译:农夫约翰的农场又迎来了美好的一天。农夫约翰来到农场后,数了数n条腿。众所周知,农场里只住着鸡和牛,一只鸡有2条腿,而一头牛有4条腿。假设约翰农场主数清了所有动物的腿,那么他的农场里最少有多少动物?思路求最少......
  • Codeforces Round 962 (Div. 3) 补题记录(A~G)
    这场Div.3难度高于平时。A#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintN=500100;inta[N];signedmain(){intT;scanf("%lld",&T);while(T--){intn;scanf("%lld",......
  • Audio Effects Settings
    前言        每一个音频输出节点都可以通过附加音频效果来改变最终声音输出的结果,该结果可能会受到效果附加顺序的影响。EffectsLow/HighPass(低通滤波器)属性说明Cutofffreq(截止频率)在Lowpass中,只会输出赫兹小于Cutofffreq的声波在Highpass中,只会输出赫兹大于......
  • Asp .Net Core 系列:详解授权以及实现角色、策略、自定义三种授权和自定义响应
    什么是授权(Authorization)?在ASP.NETCore中,授权(Authorization)是控制对应用资源的访问的过程。它决定了哪些用户或用户组可以访问特定的资源或执行特定的操作。授权通常与身份验证(Authentication)一起使用,身份验证是验证用户身份的过程,授权与身份验证相互独立,但是,授权需要一种身......
  • Codeforces Round 961
    省流:运气好没有掉分)B2Bonquet(HardVertion)(CF1995B2)事实上B1都写挂了(尖叫)处理花瓣数相差不超过1的花,可以用map存储每种花的数量,顺序遍历即可(其实是不想排序统计,好麻烦);那么如何计算最终答案呢。。。此处省略我赛时乱七八糟的一堆复杂做法,比较简单的写法是先找到一个可行的......
  • Codeforces 913 div3 A-G
    A题意分析把给定的坐标的那一行和那一列的其他所有坐标都输出来C++代码#include<iostream>usingnamespacestd;intmain(){ intt; cin>>t; while(t--){ strings; cin>>s; for(inti=1;i<=8;i++){ if(i+'0'!=s[1])cout<<s[0]<<i<<end......
  • CodeForces 1883A Morning
    题目链接:CodeForces1883A【Morning】思路    模拟,特判当密码中的某个元素为0时,用10减去当前光标的位置,并修改光标的位置为当前元素,再操作依次显示当前元素。对于其他情况则直接使用光标的位置减去目标位置,修改光标位置为当前元素,然后再操作一次显示当前元素。代码#......
  • CodeForces 1883B Chemistry
    题目链接:CodeForces1883B【Chemistry】思路    判断最多删去k个字符后剩下的部分为回文字符串,所以优先删除将个数为奇数个的相同字符删为偶数,当最后留下的字符串中,奇数个数的相同字符种类小于等于1时才会是回文字符串,如:aaabbbccc,此时个数为奇数的相同字符种类有三种,分......
  • k8s Deployment与StatefulSet:深入理解两种控制器的区别
    Kubernetes(k8s)是一个强大的容器编排平台,它提供了多种资源对象来管理容器化应用。在这些资源对象中,Deployment和StatefulSet是两种常见的控制器,它们用于不同场景下的容器应用管理。本文将深入探讨这两种控制器的区别,帮助你更好地理解它们在Kubernetes中的应用和选择。一、Kuber......
  • Oracle中查看日志的产生情况
    脚本selecttrunc(t.first_time)"Date",to_char(t.first_time,'DY')"Day",count(1),sum(decode(to_char(first_time,'HH24'),'00',1,0))"H0",sum(decode(to_char(first_time,'HH24'),'......