I've just started using LINQ with NHibernate in NHibernate 3, after previously using ICriteria.
Here's an example query:
ISession session = NHibernateSessionManager.Instance.GetSession();
var results = from project in session.Query<Project>()
where project.ProjectState == ProjectState.Archive
orderby project.ProjectNumber
select project;
return results.ToList();
How do I set that to cache? I've had a look around and other questions seem to use a different (perhaps outdated?) syntax, or perhaps I'm doing it wrong...
NHibernate will evict associated entities automatically if the association is mapped with cascade="all" or cascade="all-delete-orphan". The ISession also provides a Contains() method to determine if an instance belongs to the session cache. To completely evict all objects from the session cache, call ISession. Clear().
A fetching strategy is the strategy NHibernate will use for retrieving associated objects if the application needs to navigate the association. Fetch strategies may be declared in the O/R mapping metadata, or overridden by a particular HQL or Criteria query.
QueryOver is a strongly-typed version of Criteria, and is more NHibernate specific. Pretty much anything you can do in ICriteria can be done with QueryOver.
The NHibernate session encapsulates a unit of work as specified by the unit of work pattern.
Use the Cacheable()
extension method on your Queryable before calling ToList()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With