Tuesday, March 12, 2013

Entity Framework Wrappers – Part 2 – AppFabric and “effective caching” with EF integration aka “second level caching with EF” – simplified!

Entity Framework Wrappers – Part 2 – AppFabric and "effective caching" with EF integration aka "second level caching with EF" – simplified!

Problem statement: I want my SQL data to be cached in a way where my EF calls still work seamlessly without doing any major code change but the data is retrieved either from SQL store or a cache store if it's cached already. Also if the data is updated in my DAL layer using EF context.save() methods, it should invalidate the cache store automatically for that entity.

Solution: Use EF wrappers "http://efwrappers.codeplex.com/" and use caching provider toolkit

Rough diagram for understanding how it works (before/after):

Before:



After:




Description:
The way it works is every simple. With EF wrappers we get to create a new entity connection in the extended object context class. The new improved entity connection executes the T-SQL query generated by LINQ TO ENTITIES code against either the SQL store OR the app fabric.
For SQL store to understand the t-sql query is fine but for appfabric (or any other cache store) cannot understand the t-sql lingo :) ??? 

Bingo! The EF caching wrapper classes [EFCachingCommand.cs] creates the required methods for executing DB readers etc and before going to SQL store a small code snippet like below is injected :) which checks if the cache is already having the required result set OR entity object or anything :)

Required components:
Windows App Fabric Server (installed, configured and running) OR Azure [I haven't tried with azure yet]
VS 2010 or above
A SQL database

Reference material:
A working solution attached in zip file:Link


Tuesday, March 5, 2013

Entity Framework Provider Wrappers - trap the monster!

Entity Framework Provider Wrappers

I want to know what my entity framework code is executing under the hood?

I want to trap the SQL code entity framework is sending to my sql server and wants to inject something?

I want to profile my entity framework object context sql calls?

Answers to all above questions: http://efwrappers.codeplex.com/

A very good handful set of provider wrappers provided by Microsoft which you can plug in and start trapping EF.

I crated my own version which works as a service, provides a trappable entity framework connection to any remote client. J

#trivedimehulk@gmai.com