Giter Site home page Giter Site logo

debugoftheroad / citms.entityframeworkcore.oracle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from crazyjson/citms.entityframeworkcore.oracle

0.0 1.0 0.0 227 KB

Entity, Framework, EF, Core, Data, O/RM, entity-framework-core,Oracle

License: MIT License

C# 97.75% SQLPL 0.97% PLSQL 1.28%

citms.entityframeworkcore.oracle's Introduction

Citms.EntityFrameworkCore.Oracle

Entity, Framework, EF, Core, Data, O/RM, entity-framework-core,Oracle

Citms.EntityFrameworkCore.Oracle is an Entity Framework Core provider built on top of Oracle.ManagedDataAccess.Core. It allows us to use the Entity Framework Core ORM with Oracle. Async functions in this library properly implement Async I/O at the lowest level.

Getting Started

Here is a console application sample for accessing a Oracle database using Entity Framework:

② Put Citms.EntityFrameworkCore.Oracle into your project's .csproj file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
	<PackageReference Include="Citms.EntityFrameworkCore.Oracle" Version="1.0.0" />
  </ItemGroup>
  
</Project>

③ Implement some models, DbContext in Program.cs. Then overriding the OnConfiguring of DbContext to use Oracle database. Besides. Finally to invoking Oracle with EF Core in your Main() method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace OracleTest
{
    public class User
    {
        public int UserId { get; set; }

        [MaxLength(64)]
        public string Name { get; set; }
    }

    public class Blog
    {
        public Guid Id { get; set; }

        [MaxLength(32)]
        public string Title { get; set; }

        [ForeignKey("User")]
        public int UserId { get; set; }

        public virtual User User { get; set; }

        public string Content { get; set; }

    }

    public class MyContext : DbContext
    {
        public DbSet<Blog> Blogs { get; set; }

        public DbSet<User> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            => optionsBuilder
                .UseOracle(@"DATA SOURCE=127.0.0.1:1521/tjims;PASSWORD=test;PERSIST SECURITY INFO=True;USER ID=test;");
    }

    public class Program
    {
        public static void Main()
        {
            using (var context = new MyContext())
            {
                // Create database
                context.Database.EnsureCreated();

                // Init sample data
                var user = new User { Name = "Yuuko" };
                context.Add(user);
                var blog1 = new Blog {
                    Title = "Title #1",
                    UserId = user.UserId,
                    Tags = new List<string>() { "ASP.NET Core", "Oracle", "Citms" }
                };
                context.Add(blog1);
                var blog2 = new Blog
                {
                    Title = "Title #2",
                    UserId = user.UserId,
                    Tags = new List<string>() { "ASP.NET Core", "Oracle" }
                };
                context.Add(blog2);
                context.SaveChanges();

                context.SaveChanges();

                context.SaveChanges();

                // Output data
                var ret = context.Blogs
                    .Where(x => x.Tags.Object.Contains("Citms"))
                    .ToList();
                foreach (var x in ret)
                {
                    Console.WriteLine($"{ x.Id } { x.Title }");                
                    Console.WriteLine();
                }
            }
            Console.Read();
        }
    }
}

Contribute

One of the easiest ways to contribute is to participate in discussions and discuss issues. You can also contribute by submitting pull requests with code changes.

License

MIT

citms.entityframeworkcore.oracle's People

Contributors

crazyjson avatar huybn5776 avatar marekr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.