Repository Pattern and Unit of Work Complete implementation in 25 minutes

Поделиться
HTML-код
  • Опубликовано: 25 окт 2024

Комментарии • 8

  • @emersonstori
    @emersonstori 2 года назад

    Good...

  • @waqashijazi
    @waqashijazi 3 года назад

    how we can do it in database first approach? please share video if you can. Thanks

  • @openmindjustdoit1306
    @openmindjustdoit1306 5 лет назад

    thanks but i need to tech me this u will try applay many times please please tech me this how i can doing

  • @jayakumar2927
    @jayakumar2927 Год назад

    source code need

  • @tchnieniewiatru
    @tchnieniewiatru 4 года назад

    Source code pls

  • @MrAbudhagir
    @MrAbudhagir 4 года назад

    Source code please

    • @kollection4nomi
      @kollection4nomi 4 года назад

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      namespace repositoryPattern5.DAL
      {
      public class Repository : IRepository where TEntity : class
      {
      protected readonly RepoContext dbContext;
      public Repository(RepoContext _dbContext)
      {
      dbContext = _dbContext;
      }
      public void Add(TEntity entity)
      {
      dbContext.Set().Add(entity);
      }
      public TEntity Get(int Id)
      {
      return dbContext.Set().Find(Id);
      }
      public IEnumerable GetAll()
      {
      return dbContext.Set().ToList();
      }
      public void Remove(int Id)
      {
      TEntity entity = dbContext.Set().Find(Id);
      dbContext.Set().Remove(entity);
      }
      }
      }
      using repositoryPattern5.Models;
      using System;
      using System.Collections.Generic;
      using System.Data.Entity;
      using System.Linq;
      using System.Web;
      namespace repositoryPattern5.DAL
      {
      public class RepoContext : DbContext
      {
      public RepoContext() : base("name=RepoContext"){}
      public DbSet products { get; set; }
      }
      }
      using repositoryPattern5.Models;
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      namespace repositoryPattern5.DAL
      {
      public class ProductRepository : Repository, IProductRepository
      {
      public ProductRepository(RepoContext dbContext) : base(dbContext) { }
      public IEnumerable GetTopProducts()
      {
      return dbContext.products.Take(2);
      }
      public RepoContext repoContext
      {
      get
      { return dbContext as RepoContext; }
      }
      }
      }
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      namespace repositoryPattern5.DAL
      {
      public interface IRepository where TEntity : class
      {
      IEnumerable GetAll();
      TEntity Get(int Id);
      void Add(TEntity entity);
      void Remove(int Id);
      }
      }
      using System;
      using System.Collections.Generic;
      using System.Data.Entity.Core.Metadata.Edm;
      using System.Linq;
      using System.Web;
      namespace repositoryPattern5.DAL
      {
      public interface IUnitOfWork : IDisposable
      {
      IProductRepository products { get; }
      int Complete();
      }
      public class UnitOfWork : IUnitOfWork
      {
      private IProductRepository _products;
      public IProductRepository products { get; private set; }
      private RepoContext _dbContext;
      public UnitOfWork(RepoContext dbContext)
      {
      _dbContext = dbContext;
      products = new ProductRepository(_dbContext);
      }
      public int Complete()
      {
      return _dbContext.SaveChanges();
      }
      public void Dispose()
      {
      _dbContext.Dispose();
      }
      }
      }
      using repositoryPattern5.Models;
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      namespace repositoryPattern5.DAL
      {
      public interface IProductRepository : IRepository
      {
      IEnumerable GetTopProducts();
      }
      }
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      namespace repositoryPattern5.Models
      {
      public class Product
      {
      public int ProductId { get; set; }
      public string ProductName { get; set; }
      public string ProductType { get; set; }
      public string ProductDescription { get; set; }
      }
      }