After having an interesting discussion with Stefaan (colleague, friend, ex-colleague and now colleague again) about my previous post on NHibernate’s SQLCriterion, I decided to have another look at my usage of SQLCriterion. He argued that with SQLCriterion, you’re more or less working around the ORM, which I can agree with. After putting it on StackOverflow, I got three answers and tried all three. This is what I went with in the end: ISessionFactory sessionFactory = GetSessionFactory(); ISession session = sessionFactory.GetCurrentSession();
I recently needed to use NHibernate’s SQLCriterion, but lost some time on finding out how to use it. Once you’ve found it, it’s quite simple actually: ISessionFactory sessionFactory = GetSessionFactory(); ISession session = sessionFactory.GetCurrentSession(); ICriteria criteria = session.CreateCriteria(); var sqlString = new SqlString(“{alias}.GroupId = ” + groupId); criteria.Add(new SQLCriterion(sqlString, new object[0], new IType[0])); return criteria.List(); The {alias} is there so NHibernate knows where to put the table name. I’m not so sure about the second and third argument of the SQLCriterion
In my previous post, I explained how I went about starting with RavenDB. Now I want to continue my switch from NHibernate to RavenDB. The GetAll method was fairly simple. I also have a GetOneById method in my BaseRepository, but, as I’m not using it right now, I decided to remove it (YAGNI you know). Then, I changed the my BaseRepository to enforce the T to be a BaseEntity: public class BaseRepository<T> : IBaseRepository<T> where T : BaseEntity I thought
The application I’m writing isn’t in a very far stadium yet, but I do have some implementation of repositories using NHibernate. Now I want to switch to RavenDB. So I downloaded RavenDB (the latest build at this time – build 81) and unzipped it. I wanted to follow the RavenDB Hello World tutorial, but soon found out its built for .NET 4. I don’t have .NET 4 or Visual Studio 2010 yet, but luckily there’s a client for .NET 3.5.
WPF creates a whole new range of possibilities, but you can often run into trouble when trying to combine it with NHibernate. NHibernate can’t handle ObservableCollections*, which is a quite handy feature of WPF. Furthermore, what to do with the good databinding capabilities of WPF?Shawn Duggan provides a nice solution using the **Model-View-ViewModel **pattern here. Check out this recent article by Josh Smith for a good introduction of the MVVM design pattern (with an easy-to-follow example). it is possible to
Want intellisense for NHibernate in Visual Studio 2008? It’s easy, just download the NHibernate source here, and extract it somewhere. Go to the src/NHibernate folder and copy the following files: nhibernate-configuration.xsd nhibernate-mapping.xsd nhibernate-generic.xsdPaste these files in the Xml/Schemas folder of your VS2008 installation folder. Usually this will be C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas.