Ritesh,
No, I still have the issue. I took a look at your test and made my
test exactly like yours with no success.
1. Versions:
NHibernate - 2.1.0.4000
NHibernate.Linq - 1.0.0.4000
I do not use FluentNHibernate at all.
I do use your latest SVN copy of code and not the released stable
version.
2. I am trying to run your tests, but keep getting assert failure - as
if it doesn't get the order at all (fails on not null check). I cannot
figure out how to display SQL generated by nHIbernate when using
Fluent, so I cannot check what exactly is being run against the DB. I
checked the DB itself (took me a little to set it up and figure out
that you build actual schema from code every time you run tests, but
data is in a separate sql file) and it seems to have all data in
there, so I'm not sure what is going on at the moment. All other tests
in that file seem to run ok and I get green.
3. My tests behave the same way as before - they fail in two different
ways.
a. When I run either one of the following two variations of code,
which specify "where" clause in 2 different notations:
using (new UnitOfWorkScope())
{
NHRepository<Order> repository = new NHRepository<Order>();
Order result = (from o in repository.Query(new
Specification<Order>(o => o.Items.Any(i => i.Store == "Internet")))
where o.Id == 50
select o).FirstOrDefault();
Assert.AreEqual(7, result.Items.Count);
}
OR
using (new UnitOfWorkScope())
{
NHRepository<Order> repository = new NHRepository<Order>();
Order result = repository
.Query(new Specification<Order>(o => o.Items.Any(i => i.Store ==
"Internet")))
.Where(o => o.Id == 50)
.FirstOrDefault();
Assert.AreEqual(7, result.Items.Count);
}
my unit test hang and I eventually get NHibernate exception that I was
referring to in my original post. After I check the SQL I see that
"where" clause is being ignored and the test is trying to pull all of
the orders from the DB (I've got millions of rows in this legacy DB,
so this might be something that you cannot simulate with your test
DB).
b. The only time I get SQL that doesn't hang is when I provide 2
specifications into Query method (and leave "where" out completely):
.Query(
new Specification<Order>(o => o.Items.Any(i => i.Store ==
"Internet"))
&
new Specification<Order>(o => o.Id == 50)
)
but this code results in an incorrect SQL being generated (remember,
that I try to lazy load items): SQL for loading an Order has both
discriminators (order.Id and item.Store, even though there is no use
for item.Store at this point), but subsequent SQL for loading actual
items has only order.Id discriminator (while it should have item.Store
discriminator as well as this point). So, running this code results in
me getting ALL of the items, not only those that belong to Internet
store.
4. May I suggest not to check for item collection size against being
over 0, but to check that it is actually of an expected size? This way
you will see whether it pulls all of the items or only those that
belong to "StoreC" and I'm pretty sure that you will see that instead
of 2 elements you will end up with 6.
Well, I think I answered all of your questions and I tried to provide
as much details and input as I could think about.
Thanks a lot!
Alex