Repository and Unit of Work T4 Template for Entity Framework

Monday, July 5, 2010

Repository and Unit of Work T4 Template for Entity Framework Two weeks ago I wrote the Revisiting the Repository and Unit of Work Patterns with Entity Framework post. One thing that I thought would be nice was to have an automatic code generation that will help me to build these patterns without sweating. So I sat down and created a T4 Template to auto generate the same patterns that I showed in the post. The Code One thing to understand is that the provided T4 Template isn’t bullet proof and errors can occur (you can change the implementation as you like). In...

Eager Loading with Repository Pattern and Entity Framework

Tuesday, June 22, 2010

Eager Loading with Repository Pattern and Entity Framework One question that I received yesterday after I published the Revisiting the Repository  and Unit of Work Patterns with Entity Framework post was how to include the eager loading ability of Entity Framework. This post is offering a solution. Revisiting Eager Loading and Lazy Loading Lazy loading is a design pattern that is commonly used to defer initialization of an object up until it is needed by the program. The gains of using the pattern include efficiency (if it’s used right) and sometime performance. Eager loading is the opposite pattern of lazy loading....

Revisiting the Repository and Unit of Work Patterns with Entity Framework

Monday, June 21, 2010

Revisiting the Repository and Unit of Work Patterns with Entity Framework In the past I wrote two posts about the Repository and the Unit of Work patterns (here and here). Today I want to show a better and less naive solution for imposing the Unit of Work and the Repository patterns with Entity Framework. Revisiting The Repositoy Implementation In the Repository pattern, I added to the interface two new methods for adding and removing an entity: public interface IRepository<T> where T : class{ T GetById(int id); ...

Cache Retrieval Pattern

Sunday, June 13, 2010

Cache Retrieval Pattern In my previous post I wrote about cache layer and its position in every application. In this post I’m going to explain what is the cache retrieval pattern and show an example of how to implement it. Cache Retrieval Pattern When we implement a cache layer we need a strategy in order to retrieve cached items. The cache retrieval pattern is very simple and can be imposed into any application very fast. So how does it work? The business logic component will use the cache API in order to check whether some data exists in the cache. If the...

Cache Layer

Friday, June 11, 2010

Cache Layer Lately I found myself in some architecture consulting sessions at some customers. In every one of those customers I found myself explaining how to implement a cache layer in order to decrease the amount of round trips to the database and for better scalability. In this post I’ll try to explain in high level how to build a cache layer. Deciding to Build a Cache Layer Every application that performance is important to its developers and managers must contain some sort of caching. The cache is a veryfast in memory resources container which holds relevant data close to the application...

Using Unit of Work Pattern with Entity Framework

Friday, February 5, 2010

Using Unit of Work Pattern with Entity Framework In a previous post I explained how to create a simple repository on top of Entity Framework. In this post I’ll explain the Unit of Work pattern and how we can use it with our data access layer. What is Unit of Work Pattern? In his famous and developer must read book “Patterns of Enterprise Application Architecture”,...

Using Repository Pattern with Entity Framework

Wednesday, January 20, 2010

Using Repository Pattern with Entity Framework One of the tools for reaching for persistence ignorance is to build a facade between the data access layer and your business logic. Such facade will prevent the knowledge of how the data access is working and with which technology. That abstraction can be achieved by using the Repository Pattern. In the post I’ll...

Applying Strategy Pattern Instead of Using Switch Statements

Sunday, November 22, 2009

Applying Strategy Pattern Instead of Using Switch Statements Once in a while I’m stumbling on switch statements during a Code Review session. Whenever this is happening my first reaction is to understand why did the developer use it. Since using switch statement sometime implies spaghetti code and also can get very crowded (in case statements of course) in this post I’m going to show an alternative method that I prefer to use. Alternative Method for Switch Statements Whenever you start to use a switch statement you should ask yourself whether you can use Strategy Pattern instead. The Strategy Pattern help us to...

Do We Need Design Patterns?

Monday, September 14, 2009

Do We Need Design Patterns? In the previous week I have been asked “do we really need design patterns when we write code?”. Since one of the first things that I wrote in my blog was a design patterns series you probably would think that I answered SURE! or other absolute answer. That isn’t the case. The question was raised since I saw that a developer tried to enforce a design pattern (abstract factory)...

My Next Month Courses Schedule

Wednesday, May 13, 2009

My Next Month Courses Schedule Next month I’m scheduled for the following courses: ADO.NET Entity Framework  Scheduled for 16.6 Advanced ASP.NET 3.5 Scheduled for 14.6 Design Patterns Scheduled for 11.6 If you want to participate in one of those courses or more details, you can contact E4D in the following ways: Contact Form in the this link Call Michal - 054-5612259 ...