New user; LINQ-to-NH question

8 views
Skip to first unread message

mysterd429

unread,
Feb 28, 2011, 10:55:45 AM2/28/11
to nhusers
Hi all. I am a Java developer turned .NET developer, and I've got some
small projects that use LINQ to SQL that I'm considering switching
over to user NHibernate. (LINQ to SQL frustrates me. I spend lots of
time trying to figure out what how to write my business logic in such
a way that it doesn't depend on LINQ to SQL's oddities.) Anyway, I put
together a simple example to try most of the things I do with LINQ to
SQL to see if I can use NHibernate, and I'm impressed, but I ran into
an issue.

I posted this question on the NHibernate Users forum on the Hibernate
site, but got no reply for a few weeks. The post there is
https://forum.hibernate.org/viewtopic.php?f=25&t=1009470, and it
includes the code I used. The short version is that this:

IList<Cat> dbCats = session.Query<Cat>().Where(cat => cat.Toys.Any(t
=> t.Shape == "Bird")).ToList();

gets me this:

Could not load type cat.Toys. Possible cause: the assembly was not
loaded or not specified.

I've since downloaded the NHibernate source and compiled it with
debugging turned on using .NET 3.5. The exception occurs at
NHibernate.Util.ReflectHelper.ClassForFullName(String classFullName)
in path\to\\NHibernate-3.0.0.GA-src\src\NHibernate\Util
\ReflectHelper.cs:line 222.

Am I not understanding how this is supposed to work? This is the last
thing preventing me from switching over my new project and eventually
porting over some older projects, as well.

Thanks!

mysterd429

unread,
Mar 2, 2011, 10:14:08 AM3/2/11
to nhusers

Yiannis

unread,
Mar 2, 2011, 11:28:27 AM3/2/11
to nhusers
Well you're obviously doing the right thing by switching to NH.

Looking at the error, I'd say that it is probably caused because your
session factory doesn't know about your mapping assemblies. Make sure
that your *.hbm files are included as embedded resources and that your
session factory does indeed load the mapping assemblies either
programmatically or via XML configuration.

However if the assemblies were not loaded correctly I would expect an
exception on "tx.Commit()" not later.

On Mar 2, 3:14 pm, mysterd429 <don.lavelle.b...@gmail.com> wrote:
> Hi all. I am a Java developer turned .NET developer, and I've got some
> small projects that use LINQ to SQL that I'm considering switching
> over to user NHibernate. (LINQ to SQL frustrates me. I spend lots of
> time trying to figure out what how to write my business logic in such
> a way that it doesn't depend on LINQ to SQL's oddities.) Anyway, I put
> together a simple example to try most of the things I do with LINQ to
> SQL to see if I can use NHibernate, and I'm impressed, but I ran into
> an issue.
>
> I posted this question on the NHibernate Users forum on the Hibernate
> site, but got no reply for a few weeks.  The post there ishttps://forum.hibernate.org/viewtopic.php?f=25&t=1009470, and it

Don

unread,
Mar 3, 2011, 8:53:01 AM3/3/11
to nhusers
Yiannis,

Thanks for your reply and for your support of my switching to NH.
Unfortunately, this was an EBKAC. I had the *.pdb files in the same
folder as the NHibernate DLLs, *and* I have Visual Studio set to break
whenever an exception is thrown. So, what was happening was that
Visual Studio was seeing that, somewhere deep in the NHibernate
library, an exception was being thrown, but since I didn't have the
source for it, it showed it like my line of code was throwing the
error, and I started trying to figure out what I did wrong. After
your message, I took a look at the NHibernate code (since I knew the
*.hbm files were right, as was the mapping) and saw that it was
catching the error and continuing. When I removed the *.pdb file,
Visual Studio stopped showing me the internal error.

Perhaps the lessons here for me are 1) if I get an exception you don't
expect, see what happens if you run through it before asking for help,
and 2) don't keep *.pdb files around without keeping the code.

Cheers,

Don

On Mar 2, 11:28 am, Yiannis <yiannis.triantafyllopou...@gmail.com>
wrote:

Fabio Maulo

unread,
Mar 3, 2011, 1:54:28 PM3/3/11
to nhu...@googlegroups.com
Please send a mail to NH-dev-list with your experience deploying .pdb.
Thanks.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

Reply all
Reply to author
Forward
0 new messages