Skip to content

AJEETX/Generic.Repository.EntityFramework

Repository files navigation

Generic.Repository.EntityFramework GitHub release Maintenance

GitHub Release Date Website azy MyGet Build Status Build Status
.Net Framework GitHub language count GitHub top language GitHub repo size in bytes

Purpose of statement

In order to perform database CRUD operation from .net application, 
the wrapper makes it quite easy by following the below steps.

Steps to use the NuGet package

In VS2015 or above, Create .net application [.net4.6.1] to interact with Sql server database

  1. Search nuget package with name 'Generic.Repository.EntityFramework'.
  2. Download the NuGet through VS IDE to install in your project.
  3. Create your EntityFramework DataModel, then tweak the DataModel as below

IDbContext type is inherited from the installed NuGet package

using Generic.Repository.EntityFramework;       //add this reference
//DB is real data model created from database
public partial class DB : DbContext, IDbContext   
{ 
  public DB() : base("name=connectionstring"){} 
  IDbSet<T> IDbContext.Set<T>()
  {
  	return base.Set<T>();
  }
  public DbSet<Customer> Customers {get;set;}
  public int Save()
  {
  	return base.SaveChanges();
  }
  ....
}
  1. Now all set, please add the below lines from your consuming object/component
//add these 2 references
using Generic.Repository.EntityFramework;
using Unity;  

public class ConsumeService
{
     ...
    void ConsumeMethod()
    {           
           var container = UnityConfig.Container; //get the Unity container
             
           container.RegisterType<IDbContext, DB>(); // register your 'DataModel'
     
           var dbManager=container.Resolve<IDBManager>(); //get the db manager
     
	      //All wired up. DO YOUR CRUD OPERATION  & Customer is the table name in DB 
         
         var result=dbManager.GetRepository<Customer>().Get();  //GET	All
       
         //FIND by id, where id is the primary key
	     var result=dbManager.GetRepository<Customer>().Find(id); 

         // custObj is the Customer object
	     var result=dbManager.GetRepository<Customer>().Add(custObj); //ADD

	     var result=dbManager.GetRepository<Customer>().Update(custObj); // UPDATE

 	     var result=dbManager.GetRepository<Customer>().Delete(custObj); // DELETE
     }

Application list and details

App Name Type Comments
Generic.Repository.EntityFramework* Class Library EntityFramework wrapping business logic
Generic.Repository.EntityFramework.Test Test App unit tests
Generic.Repository.EntityFramework.ConsoleApp.Test Console Test the wrapping business logic

*nuget package "Generic.Repository.EntityFramework" is a wrapper around ORM EntityFramework


Support or Contact

Having any trouble? Check out our documentation or contact support and we’ll help you sort it out.

GitHub (Pre-)Release Date Github commits (since latest release) Downloads Downloads
HitCount GitHub contributors license