Code Monkey home page Code Monkey logo

efrepository's Introduction

EFRepository

Build status Code Coverage Technical Debt NuGet NuGet Pre Release Gitter

Generic repository and pattern "Unit of work" for Entity framework

Read more samples...

Requirements

  • .Net Framework 4.6.1
  • EntityFramework 6.1.3

Features

  • Generic Repository
    • Basic operation
      • Add
      • Add range
      • Get list
      • Get list with condition
      • Get by id
      • Get with condition
      • Update
      • Delete
      • Support generic identity
    • Asynchronous operation
      • Add async
      • Add range async
      • Get list async
      • Get list with condition async
      • Get by id async
      • Get with condition async
      • Update async
      • Delete async
    • Hooks Supports
  • Unit of work

Quick Start

  1. Install nuget package

    Install-Package KirkChen.EFRepository 
    
  2. Create data class with interface IEntity

    public class MyData : IEntity<int>
    {        
        [Key]
        public int Id { get; set; }
        
        public string Content { get; set; }
    }
  3. Create dbContext

    public class MyDbContext: DbContext
    {
        public DbSet<MyData> MyDatas { get; set; }
    }
  4. Create repository for data class

    public class MyDataRepository : GenericRepository<int, MyData>, IRepository<int, MyData>
    {
        public MyDataRepository(MyDbContext context)
            : base(context)
        {
            // Enable soft delete
            this.RegisterPostLoadHook(new SoftDeletePostLoadHook<MyData>());
            this.RegisterPostActionHook(new SoftDeletePostActionHook<MyData>());
        }
    }
  5. Use reository

    var dbContext = new MyDbContext();
    var repository = new MyDataRepository(dbContext);
    var myData = repository.Get(1);

Unit of work

Using unit of work to handle transaction

using(var dbContext = new MyDbContext())
using(var unitOfWork = new UnitOfWork(dbContext))
{
    var repository = new MyDataRepository(dbContext);
    repository.Add(data);

    var anotherRepository = new OtherDataRepository(dbContext);
    repository.Add(anotherdata);

    unitOfWork.SaveChanges();
}

Roadmap

  • Generic Repository
    • Basic operation
      • Add
      • Add range
      • Get list
      • Get list with condition
      • Get by id
      • Get with condition
      • Update
      • Delete
      • Support generic identity
    • Asynchronous operation
      • Add async
      • Add range async
      • Get list async
      • Get list with condition async
      • Get by id async
      • Get with condition async
      • Update async
      • Delete async
    • Hooks Supports
      • Nested object save changes
      • Soft delete
      • Auto system infomation
      • Audit log
      • Global query filter
  • Unit of work

efrepository's People

Contributors

kirkchen avatar

Watchers

 avatar  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.