If NHibernate decided to ditch compatibility with plain old .net 2.0 and focus on 3.5 how would the ICriteria interface change? Previously I was throwing around an idea of using a simple lambda expression to resolve the property name. Well, I couldn't help but build on this a little more. The following idea is not supposed to be LINQ, that would be far more complicated and LINQ is essentially its own interface, which is not the point. The point is, if ICriteria was written today in .net 3.5, what could it look like? How could it change?
So just to recap,...
I can't remember if this has been around before, I do vaguely remember seeing something like it.
However, I just wanted to apply a snippet of code I found on Paul's blog the other day to NHibernate. Of course we will definitely have type safety in queries when Linq-to-NHibernate is completed. But surely linq-to-nhibernate is not going to be the _only_ way of writing queries.
Using the original code snippet 'as is' would look something like this:
ICriteria c = session.CreateCriteria(typeof(Person));c.Add(Restrictions.Eq(Property.GetFor(() => new Person().FirstName), "John"));
This is ok, but a little long winded, so I implemented another class called RestrictBy which can break...
NHibernate is a remarkable ORM, however with all the magic comes a few caveats, these being the difficulties running NHibernate apps in a shared hosting environment. I'm still convinced that it's entirely possible, so I've decided to start compiling a list of success and failures that others (and myself) have had in getting things working.
Compatible Shared Hosts
Host Name
Comment
...
Every since using NHibernate, the effort required to use Many-to-many and one-to-many joins in business objects is a brainless exercise. When using a lazy loaded property on a business object, it just works, however, what happens when you try to bind this property using an ObjectDataSource hooked up to gridview or formview in asp.net...
As seen above, the GridView works out that it's out of it's depth with all the complex properties and only defines the simple text/int/boolean columns. The only alternative for the complex properties is to define your own template columns.
To display the value of a complex property...