HowTo register queries from hql embedded resources

Before we get started, you will need this file containing all the extensions methods included in this page.
You must provide a valid dialect before register the queries
  configuration.Properties[Environment.Dialect] = "NHibernate.Dialect.SQLiteDialect";

You will need a reference to the assembly you can do something like this:
 var assembly = Assembly.Load("MyAssemblyName");
 var assembly = typeof(SomeTypeInTheAssembly).Assembly;

Add just one query with an specific name:

 configuration.AddQuery(assembly, "MySuperQuery");

The query name is the same than the file name, without the file extension.
You can also provide a configuration
 configuration.AddQuery(assembly, "MySuperQuery", q => q.cacheable = true);

Add all queries from assembly

Sometimes might be quite useful, to add all queries from an assembly

Add all queries from specific namespace

You can put your queries in namespace as follows:
 configuration.AddQueriesFromNamespace(assembly, "CacheablesInFooBarRegion", q => { q.cacheable = true ; q.cacheregion = "FooBarRegion"; });

Last edited Aug 19, 2010 at 11:22 PM by jfromaniello, version 1


No comments yet.