Gallery

ajeetx

ajeetx

Generic.Repository.EntityFramework

Generic.Repository.EntityFramework GitHub release Maintenance

| GitHub Release Date | Website| ajeetx MyGet Build Status|Build Status

.Net Framework | GitHub language count| GitHub top language |GitHub repo size in bytes

Database interaction made easy

A simple dotnet application has to interact with database.
So as to do CRUD operation from .net application, 
the nuget package wrapper makes it quite easy by following the below steps.

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


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 EntityFrameworkWrapper;       //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 int Save()
        {
            return base.SaveChanges();
        }
        ....
    }
  1. Now all set, please add the below lines from your consuming object/component
using EntityFrameworkWrapper;using Unity;  //add these 2 references
public class ConsumeService
{
     ...
    void ConsumeMethod()
    {
           //get the Unity container
           var unitycontainer = UnityConfig.UnityContainer;
     
           // register your 'DataModel'
           unitycontainer.RegisterType<IDbContext, DataModel>(); 
     
           var dbManager=unitycontainer.Resolve<IDBManager>(); //get the db manager
     
	      //All wired up !!!
          DO YOUR CRUD OPERATION  & Customer is the table name in DB; 
         
         //GET	
         var result=dbManager.GetRepository<Customer>().Get();  
       
         //FIND by id, where id is the primary key
	     var result=dbManager.GetRepository<Customer>().Find(id); 

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

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

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|

Read more...

Connect to feed

By: AJEETX

Total download count: 39748495

Community