NHibernate
There are 10 entries for the tag NHibernate

Yeah, yeah, yeah, I know I shouldn’t create aggregate roots.  However, sometimes I just want to hack something together and I don’t particularly feel like wasting my time with stored procedures.  However, if you’ve got an old list and a new list and you need to sync up the changes to the database, the code to do this isn’t exactly obvious.  What’s worse, some of the error messages you get when you get it wrong are positively unhelpful.  My personal favourite is “Non-static method requires a target” (what on earth is NHibernate doing that generates that error?) but “a different...

I'll be honest, the main reason for the last post was to make sense of this one.  Consider the following code: public User UserByName(string name) { return session.Linq<Person>() .Cached() .DistinctRoot() .Expand("UserRoles") .Where(u => u.WindowsUserName == name) .FirstOrDefault(); } It's exactly what you'd hope for.  Nice and explicit: you want the first person whose windows user name matches 'name' and to pull back the person's roles at...

I don't tend to post things because they're funny, but this one was quite special.  I was interviewing someone recently and saw that they were using Entity Framework.  Now, I know very little about it, since I've expended my energy on learning NHibernate.  So, I asked "You're using Entity Framework.  What do you think of it?".  The reply I got: Actually, that's one of the reasons I'm leaving my current employer. I don't laugh out loud in interviews very often... Technorati Tags: NHibernate,Entity Framework

My previous article emphasized that you shouldn't mix clustered indexes and identity fields.  However, if you're using NHibernate you already probably know you shouldn't be using identity fields.  On the other hand, the points still generalize to some of the NHibernate generators: Increment: just as bad as identity HiLo:  better than identity, but not by much.  Don't mix with a clustered index. GUID:  Extremely random.  In fact, probably too random.  The inserts get plastered everywhere and can hurt performance. GUID Comb: Better than GUID, ...

Probably the most C# common interview question in London is "What's the difference between an abstract class and an interface?".  Let's be clear: if you use the word contract in your answer, you're not getting a job if I'm asking the question.  Contracts are a concept that doesn't directly correspond to any code construct in C#, abstract classes and interfaces are your fundamental building blocks of well written code. Here's the one word answer:  Code.  Abstract classes can have code, interfaces can't.  C#, like Java, doesn't allow you to pull code from two sources, so you can only inherit from...

Now, I have some contempt for code metrics, ever since I discovered that TFS thought that my worst code was a constructor that checked its parameters for null.  Metrics are useful indicators.  Profit is a metric used to measure the health of a company.  It's not always useful, but that's the nature of metrics, they're indicators, not hard and fast rules.  I thought it might be interesting to examine Patrick's original post about NHibnerate 2.1 which started the whole recent argument about maintainability. First, he took a look at the number of changes to the code base.  There's been a phenomenal...

I've already talked about Patrick's measures of code quality.  His approach is to take a very direct mathematical and analytical approach to it.  I appreciate the sophistication of the tools he's using, but I think that the results of this kind of analysis need to be treated with the same level of suspicion as an analyst treats a set of accounts.  e.g. Cash flow is hard to fake, but why are the accruals so low? Ayende, on the other hand, argues for a very different approach.  He lists as his measures of code quality: Peer code review (especially...

Did someone declare it "talented developers talk rubbish" week when I wasn't paying attention?  Maybe I wasn't on the mailing list... *sigh* First we had the extremely smart Frans Bouma talking about the importance of proving your algorithms as a development methodology, which at least had the virtue of being funny.  We then had one of the single most productive developers in Alt.Net talking absolute garbage about maintainability.  At least Patrick Smacchia is still talking sense.  Let's go back to what Ayende's saying.  Maintainable is a value that can only be applied by someone who is familiar with the codebase. This...

It's even documented, right here.  It's a bit annoying, seeing as it violates the principle of least surprise, but it does make the DateTime type portable across database implementations.  However, if you want to just use your native precision, just declare it as having "Timestamp" type.  Problem solved.  No need to mess around with IUserType or worse. Technorati Tags: NHibernate

One of the most useful things you can do when setting up an NHibernate environment is to sort out of the XSDs so that Intellisense works in Visual Studio.  Note that the documentation is rather out of date.  Most people are now using the 2.2 schema, not the 2.0 schema, and the Visual Studio directory in 2008 is C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas.  Especially notice the ".0", which is new. Sorting this out not only allows you to more quickly see errors in your HBM files (a major benefit in itself) but also enables one of my favourite learning approaches: Intellisense...