Summary

There are multitude of different ways of retrieving data in NHibernate. These can be mainly divided into two types. First type consists of ISession.Get<T> and ISession.Load<T>, which you can use when you know the id of the entity you want to retrieve. Both of these can be the fastest ways of retrieving an entity from database. These are used by NHibernate internally. Second type of data retrieval methods in NHibernate are geared towards complex situations that go beyond loading entities by their id. HQL, Criteria API, QueryOver, and LINQ, all let you write complex queries in an intuitive way using object-oriented APIs. These let you load entities by properties other than ID or even combination of properties, join two or more entities, and so on. NHibernate does a lot of heavy lifting for you when it comes to writing complex queries, making the job of writing queries very easy. Querying capabilities of NHibernate are not limited to only complex queries. You can aggregate results, project results into different C# types, order or paginate results, and so on.

Data retrieval is the last major concept that you needed to learn before you can dive into more advanced and interesting topics. In this chapter, we have tried to cover most important areas of data retrieval features offered by NHibernate. But data retrieval is a complex topic and if one wants, an entire book can be written on NHibernate features around this area. While that is beyond the scope of this book, this chapter has touched upon basic building blocks that you will need to master the topic. I encourage readers to explore this area more as they use NHibernate in their work or hobby projects more and more.

In next few chapters, we will step away and try to look at bigger picture and invest our time in learning how to use NHibernate in real life projects, guidelines around using NHibernate most effectively and efficiently, recommended design patterns while working with NHibernate, and so on. Going through these chapters will help you connect the dots and get an overall picture of how to best fit NHibernate into architecture of your application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset