I can't be certain as I haven't got VB installed to test this, but it
certainly appears to be the case. Linq to NHibernate's unit tests are all in
C# so it doesn't surprise me that the differences in VB's expression trees
have been missed.

2009/1/5 RalyDSM <j...@glmotorsports.net>

>
> so I guess i need to take this problem to the linq-to-nhibernate
> guys...
>
> On Jan 5, 3:19 pm, "Jeremy Skinner" <jer...@jeremyskinner.co.uk>
> wrote:
> > Yep, you'll notice there's no where clause on the query. Its loading the
> > entire table then performing an in-memory linq query.
> >
> > 2009/1/5 RalyDSM <j...@glmotorsports.net>
> >
> >
> >
> > > are you SURE about the compile thing? When I turn on the show_sql
> > > property in NHibernate this is the query that is written:
> > > SELECT this_.Id as Id2_0_, this_.Title as Title2_0_ FROM [Product]
> > > this_
> >
> > > On Jan 5, 3:04 pm, "Jeremy Skinner" <jer...@jeremyskinner.co.uk>
> > > wrote:
> > > > I don't think this is an issue with the Repository, rather an issue
> with
> > > > Linq to NHibernate. The VB and C# compilers (unhelpfully) create
> > > expression
> > > > trees differently. My guess is the Linq to NHibernate code does not
> parse
> > > VB
> > > > expression trees correctly (I can't verify this as I don't have VB
> > > installed
> > > > on this machine).
> >
> > > > You don't want to be calling where.Compile() - this causes the
> expression
> > > > tree to be compiled into a delegate and can no longer be translated
> into
> > > SQL
> > > > - instead this ends up loading the entire table into your application
> and
> > > > then doing an *in-memory* filter (bypassing Linq to NHibernate's
> > > expression
> > > > tree parsing).
> > > > Jeremy
> > > > 2009/1/5 James Gregory <jagregory....@gmail.com>
> >
> > > > > That's very interesting. Unfortunately, the bits in the Framework
> > > > > project are rather neglected, so there may very-well be a bug in
> > > > > there. I need to investigate this before I can pass judgement
> though.
> >
> > > > > On 1/5/09, RalyDSM <j...@glmotorsports.net> wrote:
> >
> > > > > > I think I might have found a bug, but I'm not really sure. It
> could
> > > be
> > > > > > a syntax error on my part, but the compiler isn't catching.
> Anyway,
> > > > > > here is what I'm trying to do. Basically I've written my own
> > > > > > repository class that essentially just wraps the Fluent
> Repository
> > > > > > class. So here is the relevant code:
> >
> > > > > > Public Class GenericRepository(Of T As IHasIntId)
> >
> > > > > >     Private _fluentRepos As
> FluentNHibernate.Framework.IRepository
> >
> > > > > >     Public Sub New(ByVal FluentRepository As
> > > > > > FluentNHibernate.Framework.IRepository)
> > > > > >         _fluentRepos = FluentRepository
> > > > > >     End Sub
> >
> > > > > >     Private Sub New()
> >
> > > > > >     End Sub
> >
> > > > > >     Public Function GetById(ByVal Id As Integer) As T
> >
> > > > > >         Return Query(Function(x As T) (x.Id = Id)).FirstOrDefault
> >
> > > > > >     End Function
> >
> > > > > >     Public Function Query(ByVal w As Expression(Of System.Func(Of
> T,
> > > > > > Boolean))) As IList(Of T)
> >
> > > > > >         Return _fluentRepos.Query(Of T)(w).ToList()
> >
> > > > > >     End Function
> >
> > > > > > End Class
> >
> > > > > > Then I wrote two unit tests, one that would pass in an
> > > > > > InMemoryRepository and one that would use an actual NHibernate
> > > session
> > > > > > to hit the real database.
> >
> > > > > > here they are:
> >
> > > > > >   <TestMethod()> Public Sub InMemoryTest()
> >
> > > > > >         Dim inmemRepos As New InMemoryRepository()
> >
> > > > > >         Dim p As New Product()
> > > > > >         Dim id As Integer = 5
> > > > > >         p.Id = id
> > > > > >         p.Title = "my product"
> >
> > > > > >         inmemRepos.Save(p)
> >
> > > > > >         Dim genRepos As New GenericRepository(Of
> Product)(inmemRepos)
> >
> > > > > >         Dim foundP = genRepos.GetById(id)
> >
> > > > > >         Assert.AreEqual(p.Title, foundP.Title)
> >
> > > > > >     End Sub
> >
> > > > > >    <TestMethod()> Public Sub DatabaseTest()
> >
> > > > > >         Dim session =
> NHibernateSessionManager.Instance.GetSession()
> >
> > > > > >         Dim flRepos As New Repository(session)
> > > > > >         Dim genRepos As New GenericRepository(Of
> Product)(flRepos)
> >
> > > > > >         Dim id As Integer = 1
> >
> > > > > >         Dim p = genRepos.GetById(id)
> >
> > > > > >         Assert.IsNotNull(p)
> > > > > >         Assert.AreEqual(id, p.Id)
> >
> > > > > >     End Sub
> >
> > > > > > The InMemoryTest passed, and the DatabaseTest failed. The
> exception
> > > > > > from the DatabaseTest was a type conversion, from int to product
> (or
> > > > > > maybe the other way around.) I was able to "fix" it though. In
> the
> > > > > > Fluent NHibernate code I changed the Query method on the
> Repository
> > > > > > class from:
> >
> > > > > > return _session.Linq<T>().Where(where).ToArray();
> >
> > > > > > to
> >
> > > > > > return _session.Linq<T>().Where(where.Compile()).ToArray();
> >
> > > > > > Now both tests pass. All of the unit tests in the Fluent
> NHibernate
> > > > > > project pass either way.
> >
>

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

Reply via email to