Posts
Showing posts from February, 2019
IGenricRepository
- Get link
- X
- Other Apps
public interface IRepository<T> { IEnumerable<T> GetAll(); IEnumerable<T> Find(Expression<Func<T, bool >> query); T GetByID( int id); void Add(T item); void Update(T item); void Delete(T item); } public interface IGenericRepository<T> where T : class { IQueryable<T> GetAll(); IQueryable<T> FindBy(Expression<Func<T, bool>> predicate); void Add(T entity); void Delete(T entity); void Edit(T entity); void Save(); }
GenricRepository Sample No. 3
- Get link
- X
- Other Apps
using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; namespace GR.Data { public class Repository < T > : IRepository < T > where T: BaseEntity { private readonly ApplicationContext context; private DbSet < T > entities; string errorMessage = string.Empty; public Repository(ApplicationContext context) { this .context = c...
Article No. 4. Generic Repository
- Get link
- X
- Other Apps
How to Work With Generic Repositories on ASP.NET MVC and Unit Testing Them By Mocking In this blog post we will see how to work with generic repositories on ASP.NET MVC and unit testing them by mocking with moq @ 12-22-2011 by Tugberk Ugurlu ASP.NET MVC C# DbContext Entity Framework Unit Testing I have blogged about Generic Repository Pattern - Entity Framework, ASP.NET MVC and Unit Testing Triangle but that blog post only contains how we can implement that pattern on our DAL (Data Access Layer) project. Now, let’s see how it fits into our ASP.NET MVC application. I created a sample project which basically has CRUD operations for Foo class and I put the complete code of the project on GitHub . https://github.com/tugberkugurlu/GenericRepoWebApp So, in the previous blog post we have created our DAL project and repository classes based on our generic repository. I have ...