Skip to content

RepositoryPattern - UnitOfWork - ServicePattern - SqlDataOperation

Notifications You must be signed in to change notification settings

kalebasiyakup/Orcus.DataAccess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Orcus.DataAccess

Projeyi indirmeniz halinde içindeki test projesi ile istediğiniz detaylı bilgiye ulaşabilirsiniz.

Unit Of Work İle Repository Pattern Kullanımı

var context = new NORTHWNDEntities();
using (IUnitOfWork unitOfWork = new UnitOfWork(context))
{
    unitOfWork.BeginTransaction();
    var customerRepository = unitOfWork.Repository<Customers>();
    customerRepository.Insert(new Customers
    {
        CustomerID = "125",
        CompanyName = "Deneme - CompanyName"
    });
    unitOfWork.SaveChanges();
}
var context = new NORTHWNDEntities();
using (IUnitOfWork unitOfWork = new UnitOfWork(context))
{
  IRepository<Customers> customerRepository = unitOfWork.Repository<Customers>();
  var retVal = customerRepository.GetFirstOrDefault();
}

Unit Of Work İle Service Pattern Kullanımı

var context = new NORTHWNDEntities();
using (IUnitOfWork unitOfWork = new UnitOfWork(context))
{
    unitOfWork.BeginTransaction();
    var customerService = new CustomerService(unitOfWork);
    customerService.Insert(new Customers
    {
        CustomerID = "125",
        CompanyName = "Deneme - CompanyName"
    });

    unitOfWork.SaveChanges();
}
var context = new NORTHWNDEntities();
using (IUnitOfWork unitOfWork = new UnitOfWork(context))
{
    var customerService = new CustomerService(unitOfWork);
    var result = customerService.GetFirstOrDefault();
}

Service Pattern İçeriği;

public interface ICustomerService : IService<Customers>
{
    IEnumerable<Customers> CustomersByCompany(string companyName);
}

public class CustomerService : Service<Customers>, ICustomerService
{
    private readonly IRepository<Customers> _repository;

    public CustomerService(IUnitOfWork unitOfWork) : base(unitOfWork)
    {
        _repository = unitOfWork.Repository<Customers>();
    }

    public IEnumerable<Customers> CustomersByCompany(string companyName)
    {
        return _repository.CustomersByCompany(companyName);
    }
}

About

RepositoryPattern - UnitOfWork - ServicePattern - SqlDataOperation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages