Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent nHibernate - trying to cache a select statement
    primarykey
    data
    text
    <p>I am trying to cache a select statement with no success.</p> <p>I have this entity</p> <pre><code>public class Merchant : Entity&lt;Merchant&gt; { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual string Email { get; set; } public virtual string OrdersEmail { get; set; } public virtual string Host { get; set; } } </code></pre> <p>The mapping is like this</p> <pre><code>public class MerchantMap : ClassMap&lt;Merchant&gt; { public MerchantMap() { Id(m =&gt; m.Id); Map(m =&gt; m.Name); Map(m =&gt; m.OrdersEmail); Map(m =&gt; m.Email); Map(m =&gt; m.Host); Cache.ReadWrite(); ReadOnly(); } } </code></pre> <p>. The session factory is produced with this class:</p> <pre><code> public ISessionFactory TenantConfiguration() { var connectionString = System.Configuration .ConfigurationManager .ConnectionStrings["Tenant"] .ConnectionString; var config = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(connectionString) ) .Mappings(cfg =&gt; cfg.FluentMappings .AddFromAssemblyOf&lt;Entities.Merchant&gt;() ) .Cache(c =&gt; c.UseQueryCache() .UseSecondLevelCache() .ProviderClass&lt;NHibernate.Cache.HashtableCacheProvider&gt;() .RegionPrefix("Tenant") ) .ExposeConfiguration(c =&gt; c.SetProperty( NHibernate.Cfg .Environment .SessionFactoryName, "Tenant") ) .BuildConfiguration(); var factory = config.BuildSessionFactory(); return factory; } public ISession CreateMerchantSession() { lock (factorySyncRoot) { return TenantConfiguration().OpenSession(); } } </code></pre> <p>The only query i want to cache is the following one:</p> <pre><code>var merchants = new TenantSessionSource().CreateMerchantSession() .QueryOver&lt;Merchant&gt;() .Cacheable().Future().ToList(); </code></pre> <p>I have tried almost everything and have red all the related questions but with no success. From the nhibernate profiler i see that everytime it opens a new session and executes this query repeatedly.</p> <p>Any ideas? Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload