Posts

Showing posts from February, 2019

All in One : Mosh Course EF in Depth

Image

GenericRepo Sample No. 4

Image

IGenricRepository

Image
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

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...

GenericRepository Sample No. 2

public   class  GenericRepo : IGeneric<Student,  int >,IDisposable      {           private  StudentContext db;           public  GenericRepo()          {               this .db =  new  StudentContext();          }           public  List<Student> SelectAll()          {               return  db.Students.ToList();          }           public  Student SelectByID( int  id)...

Article No. 4. Generic Repository

Image
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 ...