Hi. 

I'm currently using NHibernate as an access layer for a legacy database and 
it actually works quite well. But now i ran into a problem and i'm 
completely at a loss how to fix it or even why it is happening. 

So here is a basic project that shows the behavior i want to have. 

https://github.com/thomaslazar/NHibernateThenFetchManyTest

I constructed it by going through this FluentNHibernate Getting Started 
tutorial here. 
https://github.com/jagregory/fluent-nhibernate/wiki/Getting-started
Made a few changes to suit my problem and it basically just works as 
advertised. 

So i have basically this database model: 

jobTable <--- n:1 --- maintenanceObjectTable --- n:1 ---> componentTable

So a maintenanceObject can have many components and many jobs. 

I want to make a query that loads me a couple of jobs, and then eager 
fetches the objects and the components in one go. 

So the linq query is like: 
session.Query<jobs>.fetch(x=>x.maintenanceObject).ThenFetchMany(x=>x.
components)
 
When i use a loop to print out the data i just queried i expect to see 
something like this:

job1 
  maintenanceObject1
     component1
     component2 
     component3
job2
  maintenanceObject1
     component1
     component2 
     component3
job3 
  maintenanceObject1
     component1
     component2 
     component3
job4
  maintenanceObject2
     component4
     component5 
job5
  maintenanceObject2
     component4
     component5 


With the linked project above that's the case. All works just fine and i'm 
happy. 

Now here comes this project: 
https://github.com/thomaslazar/NHibernateTestSipModel

With it i tried basically the same stuff and just have it go onto my legacy 
database. Just the class names changed a bit. The Entity properties are a 
bit different, but the relations are basically the same. 
It didn't work. Instead of the expected output i got a Cartesian Product on 
the component level. So for every "job" referencing the same 
"maintenanceObject" i got another set of "components". 

So the above result looked like that. 

job1 
  maintenanceObject1
     component1
     component2 
     component3
     component1
     component2 
     component3
     component1
     component2 
     component3
job2
  maintenanceObject1
     component1
     component2 
     component3
     component1
     component2 
     component3
     component1
     component2 
     component3
job3 
  maintenanceObject1
     component1
     component2 
     component3
     component1
     component2 
     component3
     component1
     component2 
     component3


Then i tried reducing the areas that could cause the problem. 
The legacy database is running on an mssql server. So i ripped that stuff 
out and made the project use a sqlite database like in the first project. I 
had to fill it with test data now but the query showed the same false 
result. 

Ok. The mapping had Table and Column definitions in it that i needed for 
the legacy database. Commented them out. Still the same. 

I changed the way the first program saved the data. Still working there. 

I fiddled around on both projects to either make the not working one work 
properly... or make the other one break... 

Both projects use the same NHibernate, FluentNHibernate, SQLite and 
NHibernate Profiler Appender packages from nuget... 

I'm really at a loss here. I need this stuff to work... 

I even had FluentNHibernate generate hbm.xml files to compare with my 
actual application model (which uses xml configuration instead of fluent) 
to see if i made a mistake modeling that stuff. But it's basically the same.

It's probably some stupid thing like "you missed a comma here!". But i 
can't see it. Had a colleague look over both projects, and he couldn't find 
anything either. 

So help would really really really be appreciated. 

Best regards
Ibn



















-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to