I am using nhibernate and I have a question.
Say I have an object(ObjectA) that has some relationship to another object(ObjectB).
ObjectA -开发者_开发技巧> TableA
ObjectB -> TableB
Now I do a query and get back results from TableA and now it's in ObjectA.
If I did this
int b = ObjectA.ObjectB.ColumnA;
it would go off and fire a query right? Since it is doing lazy loading.
what happens if I did this
int b1 = ObjectA.ObjectB.ColumnA;
int b2 = ObjectA.ObjectB.ColumnA;
int b3 = ObjectA.ObjectB.ColumnA;
int b4 = ObjectA.ObjectB.ColumnA;
this is all in the method method one after another. Would you go and do 5 queries or would it just do one?
How about if I did this
int b1 = ObjectA.ObjectB.ColumnA;
string b2 = ObjectA.ObjectB.ColumnB;
would this fire off 2 queries or one?
All those methods result in just one call, to load ObjectB.
After that, it's in memory; why would it go to the DB again?
It also depends on Nhibernate mapping mentioned for ColumnA & ColumnB for ObjectB. IF they happen to mapped to a separate class/entity with lazy load set to true, then when Object B is loaded, ColumnA & ColumnB mapped entities are not loaded. They will be loaded by Nhibernate only when they are accessed.
精彩评论