NHibernate Facility 2RC & NHibernate 3.1

132 views
Skip to first unread message

Vladimir Kalinkin

unread,
Mar 30, 2011, 10:40:53 PM3/30/11
to Castle Project Users
Today I've moved to using NHibernate Facility 2RC & NHibernate 3.1
instead of NH3.0 & previous version of NH Facility
I have simple query

var query = from u in Collection
where u.Email == email
select u;
return query.Single();

It throws NullReferenceException here (d:\CSharp\NH\NH\NHibernate\src
\NHibernate\Linq\NhQueryProvider.cs):

private NhLinqExpression PrepareQuery(Expression expression, out
IQuery query, out NhLinqExpression nhQuery)
{
var nhLinqExpression = new NhLinqExpression(expression);

query = _session.CreateQuery(nhLinqExpression); //
_session==null !!

nhQuery =
query.As<ExpressionQueryImpl>().QueryExpression.As<NhLinqExpression>();

SetParameters(query, nhLinqExpression.ParameterValuesByName);
SetResultTransformerAndAdditionalCriteria(query, nhQuery,
nhLinqExpression.ParameterValuesByName);
return nhLinqExpression;
}

We have session=null after:

public static IQueryable<T> Query<T>(this ISession session)
{
return new NhQueryable<T>(session as ISessionImplementor);
}

In NH 3.0 it was:

public static IQueryable<T> Query<T>(this ISession session)
{
return new NhQueryable<T>(session);
}

Every time we use SessionDelegate from the Facility which doesn't
implement interface ISessionImplementor.

Do you have any ideas how to resolve this issue?


Maximilian Raditya

unread,
Mar 30, 2011, 11:52:25 PM3/30/11
to castle-pro...@googlegroups.com
On Thu, Mar 31, 2011 at 9:40 AM, Vladimir Kalinkin <cyber...@gmail.com> wrote:
We have session=null after:

public static IQueryable<T> Query<T>(this ISession session)
       {
           return new NhQueryable<T>(session as ISessionImplementor);
       }

 
 
I think you should try this instead:
 
public static IQueryable<T> Query<T>(this ISession session)
{
    return new NhQueryable<T>(session.GetSessionImplementation());
}
 
Internally in NHibernate code base, that's how DetachedCriteria.GetExecutableCriteria(ISession) works.
 
Also ISessionImplementor is for NHibernate internal session implementation. The external interfaces for accessing session are only ISession and IStatelessSession AFAIK. So SessionDelegate (nor StatelessSessionDelegate) wouldn't implement ISessionImplementor since they are external to NHibernate code base.
 
Still, I'm not sure why it worked in NHibernate 3.0.
 
 


--
Regards,

Maximilian Haru Raditya

Vladimir Kalinkin

unread,
Mar 31, 2011, 6:08:57 AM3/31/11
to Castle Project Users
Thank you. As you see I use "Collection" (I'm sorry, it is wrapper for
Session.Query<User>()), instead of this now I'm using something like
this:

public static IQueryable<T> Collection
{
get
{
return new NhQueryable<T>(session.GetSessionImplementation());
}
}



On Mar 31, 7:52 am, Maximilian Raditya <m4h...@gmail.com> wrote:
> On Thu, Mar 31, 2011 at 9:40 AM, Vladimir Kalinkin <cyberkal...@gmail.com>wrote:
>
> > We have session=null after:
>
> > public static IQueryable<T> Query<T>(this ISession session)
> >        {
> >            return new NhQueryable<T>(session as ISessionImplementor);
> >        }
>
> I think you should try this instead:
>
> public static IQueryable<T> Query<T>(this ISession session)
> {
>     return new NhQueryable<T>(*session.GetSessionImplementation()*);
>
> }
>
> Internally in NHibernate code base, that's how
> DetachedCriteria.GetExecutableCriteria(ISession) works.
>
> Also ISessionImplementor is for NHibernate *internal *session
> implementation. The *external *interfaces for accessing session are only
Reply all
Reply to author
Forward
0 new messages