Posts

Summary of All Data Source Patterns

Simple Active Record (No Repository ) == RDG++ Simple Data Mapper (No Repository) ==  TDG++ Respository Based Active Record = Simple Active Record++ Repository Based Data Mapper = Simple Data Mapper++ Respository (Active Record) = Simple Active Record++ Repository (Data Mapper) = Simple Data Mapper++ When we are using ADO.NET and writing our own DAL, we are not using any ORM. We are dealing ourself with all dirty work of Data Access Writing SQL,Connections, Resultset fetching n mapping, exceptions, messaging, casting, transactions,updating the database schema and domain model ourself ORMs try to abstract these things out and make our life easy Linq like language for quering data. No connection management No Result set dealing and mapping to Domain Model No exception handling No messages to upper layers No Data type casting No Transation Mgmt, it is done by UOW and Change Tracker Database schema and Domain is synched by Code First Migrations Two Types of ...

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