Archive for the ‘NHibernate’ Category
(N)How simple could that be?

Wonder how this report get produced from model above it? If you guess was
- NHibernate
- MR (did you say <table>?)
You right and I must say I finally master the NH Projection skill or in another word (stealling from JXII) level up!.
What I did by taking AreaCode as primitive data connect it through and transform set of progress records into columns pretty cool trick, no NH hack is required it all natural.
Happy Projections day
Storm The Castle
I hope Ayende won’t mind if I steal the name :D well, he did used that name for one of his sample project. Anyway let me throw some good news out to all of my blog trackers “who loves coding :D” I just check-in a sample project using Castle minutes ago.
As I am not sure how many of you understand what I am blogging about or even had trouble try to replicate my trip. Now I make it simpler if you want to catch-up or debate with me on my future Castle posts you got a chance to start it now just go grab a stick and stone from http://code.google.com/p/storm-the-castle/
If you have any question/suggestion/request you can post it on the project site I am happy to help it out as time allow ;)
Oh by the way this is my 100 posts :))
Happy Chinese New Year everyone.
Many to many lazzziii
I scratched my head for a few hours reading between the line of the following code
DetachedCriteria filter = DetachedCriteria.For(typeof(Project))
.Add(Expression.Eq("ID", pid))
.SetProjection(Projections.Property("Type"));
DetachedCriteria q = DetachedCriteria.For(typeof(List_Output), "op")
.CreateCriteria("ProjectTypes")
.Add(Subqueries.Exists(filter));
ISession s = holder.CreateSession(typeof(List_Output));
IList result;
try{
result = q.GetExecutableCriteria(s).List();
}finally{
holder.ReleaseSession(s);
}
Wonder why It generate so many sql call to the server? the domain objects in discussion are Project which belong to a Type and base on selected Type a project can choices a bunch of Outputs.
So Project is belong to a Type [One-to-Many], and Type has many Outputs where Output belong to Many Types [Many-to-Many].
After a while I found the issue and got it fixed “it is the Lazzzzzzzziiiiiiiiiiiiiiiines” configuration :))
I forgot to tell Type to load Outputs in a Lazy mode and vise versa, once configured I got only one YEAH ! I mean ONE (a single) sql call to the server instead of 2 + N (where N is number of relevant Outputs in a Type)
Thanks to DetachedCriteria & the Laziness until next time don’t forget the magic word is “Lazy = true”
Woh Woh storedprocedure no more …
Read the title and want to know how to do that? come with me hacking the Castle code base or to be accurate hack NHibernate code base, what you need to bring along? not much but a SubVersion, NAnt, MbUnit and NUnit that sound enough ;)
Enjoy plug & play your database and let the Jedi rise
Happy Friday everyone !
