Gallery
![ajeetx](https://mygetwwwmain.blob.core.windows.net/feedicons/ajeetx.png?202412181258)
ajeetx
Generic.Repository.EntityFramework
Generic.Repository.EntityFramework
![Maintenance](https://img.shields.io/maintenance/yes/2018.svg?style=for-the-badge)
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
package
In VS2015 or above, Create .net application [.net4.6.1] to interact with Sql server database
- Search nuget package with name 'Generic.Repository.EntityFramework'.
- Download the
through VS IDE to install in your project.
- Create your EntityFramework DataModel, then tweak the DataModel as below
IDbContext type is inherited from the installed 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();
}
....
}
- 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.