Ich verwende FluentNhibernate
Version 2.0.3.0
und ich versuche, den Cache zu konfigurieren, um mit queries
zu verwenden, verwende ich HQL
. Ich möchte eine Meinung, wenn ich alle Konfigurationen in Ordnung getan habe, und ich möchte wissen, wie ich sehen könnte, ob Cache aktiviert war?Cache-Konfigurationen von FluentNHibernate?
Verbindung
FluentConfiguration _config = Fluently.Configure()
.Database(
MySQLConfiguration.Standard.ConnectionString(
x => x.Server(HOST)
.Username(USER)
.Password(PASSWORD)
.Database(DB)))
.Cache(c => c.ProviderClass(typeof(NHibernate.Cache.HashtableCacheProvider).AssemblyQualifiedName)
.UseQueryCache())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<UsuarioMap>())
.ExposeConfiguration(cfg => new SchemaUpdate(cfg)
.Execute(false, true));
Mapping
public class UsuarioMap : ClassMap<Usuario> {
public UsuarioMap() {
Table("USUARIOS");
Cache.ReadWrite();
Id(u => u.id).GeneratedBy.Native();
Map(u => u.nome).Not.Nullable().Length(50);
Map(u => u.email).Unique().Not.Nullable().Length(255);
Map(u => u.senha).Not.Nullable();
Map(u => u.status).CustomType<int>();
Map(u => u.dtCadastro).CustomType<DateTime>();
Map(u => u.dtLastLogin).CustomType<DateTime>();
Map(u => u.tipo).CustomType<int>();
Map(u => u.imagem);
Map(u => u.loginBy).CustomType<int>();
Map(u => u.idFacebook);
}
}
HQL Abfrage
public class UsuarioDAO : GenericDAO<Usuario>{
/** retorna todos os objetos */
public IList<Usuario> findAll(){
ISession _session = getSession();
IList<Usuario> list = _session.CreateQuery("FROM Usuario u ORDER BY u.nome")
.SetCacheable(true).SetCacheMode(CacheMode.Normal)
.List<Usuario>();
return list;
}