Quantcast
Channel: Fluent NHibernate caching with automapping - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Nick Patterson for Fluent NHibernate caching with automapping

$
0
0

Assuming you've already downloaded a 2nd-level cache provider from the NHibernate Contribution project, you should be able to use the following to initialize the cache within your automappings setup.

Configuration config = Fluently.Configure()
.Database
(
    MsSqlConfiguration.MsSql2005
    .ConnectionString(@"[MY CONNECTION STRING]")
    .Cache(c => c.UseQueryCache().ProviderClass<YourCacheProviderOfChoice>())
)
.Mappings(m => m.AutoMappings.Add(model))
.BuildConfiguration();

Selecting the queries you want to cache is simply a matter of calling SetCacheable(true) on your Criteria instance.

 var query = session.CreateQuery("from Blog b where b.Author = :author")
    .SetString("author", "Gabriel")
    .SetCacheable(true);
 var list = query.List<Blog>();

This is an epic blog post on NHibernate's first and second level caches, good reference material.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>