Dec 10, 2011 at 3:58 PM
Edited Dec 10, 2011 at 10:40 PM
@xtremebiz, I was thinking about your comment to add the caching to Enterprise Library and my first thought was that it probably won't be happening through an optional update.
My second thought was that we could do it ourselves (in a manner)!
Just create an extension method:
public static class DatabaseExtensions
public static IEnumerable<T> ExecuteSqlStringAccessor<T>(this Database database, string sqlString) where T : new()
RowMapperCache mapperCache = EnterpriseLibraryContainer.Current.GetInstance<RowMapperCache>();
IRowMapper<T> mapper = mapperCache.GetCachedMapper<T>();
return database.ExecuteSqlStringAccessor<T>(sqlString, mapper);
Now, the data access code looks just like "vanilla" Enterprise Library data access code except that we are using our extension method with caching.
public static IEnumerable<Region> GetRegions()
var db = EnterpriseLibraryContainer.Current.GetInstance<Database>();
return db.ExecuteSqlStringAccessor<Region>("SELECT * FROM Region").ToList();
If you want to revert to the base functionality (or if the caching functionality is included in a future release) then just remove the new extension method
and the Enterprise Library extension method will be called without any changes to the data access code at all.
If there are any issues with resolving between the new extension method and the Enterprise Library extension method then see
this answer on Stack Overflow.
Enterprise Library support engineer