Friday, July 26, 2013

NHibernate.TransientObjectException : object references an unsaved transient instance - save the transient instance before flushing.

I came across this error recently and found the following on nhforge:

When a transaction is committed, the session is flushed to the database. That just means data changes are written to the database. This exception is telling us we’re trying to save an object, which is referenced another object that isn’t saved. We can infer that this means cascading is turned off for this relationship. 

Reference: http://nhforge.org/blogs/nhibernate/archive/2009/08/23/part-5-fixing-the-broken-stuff.aspx

Thursday, March 7, 2013

GroupBy Multiple Columns in LINQ

How do you  GroupBy Multiple Columns in LINQ? 

The solultion is pretty simple:
Given a collection of Books where each book has an Author and a Name, if you have group group by all authors then by the name of the book, you can do


Books.GroupBy(book => new { book.Author, book.Name });