I can't think of a better way to do it.

For Single, this is the behavior:
- Request at most 2 records from the server (to avoid doing extra work)
- If no records returned, exception
- If one record returned, map it and we're done
- If more than one record returned, exception

For SingleOrDefault is the same, only the first case returns null.

How would you improve it?

   Diego


On Mon, Jul 5, 2010 at 12:32, Fabio Maulo <[email protected]> wrote:

> There is no need to complicate the query for "Single"
>
> --
> Fabio Maulo
>
>
> El 05/07/2010, a las 12:16, Diego Mijelshon <[email protected]>
> escribió:
>
> IIRC, Single/SingleOrDefault use SetMaxResults(2), and then checks that a
> single record is returned...
>
>    Diego
>
>
> On Mon, Jul 5, 2010 at 10:19, Fabio Maulo < <[email protected]>
> [email protected]> wrote:
>
>> For "First" and "FirstOrDefault" we can apply SetMaxResults(1) ... and fix
>> the bug (please check last JIRAs and add a new one if you can't find an
>> existing)
>>
>> For "Single" and "SingleOrDefault" we *shouldn't* apply SetMaxResults(1)
>> because doing so we will change the "Single" behavior (it should throw
>> exception when there are more than one results)
>>
>>
>> On Mon, Jul 5, 2010 at 10:11 AM, andrew6072 <<[email protected]>
>> [email protected]> wrote:
>>
>>> Hi Fabio,
>>>
>>> What do you mean by changing the meaning of Single ?
>>>
>>> Oh and It also happens with First(), and SingleOrDefault() as well
>>>
>>> It seems to be something to do with this call
>>>
>>> bool useLimit = UseLimit(selection, dialect);
>>> when I use Query<> it returns true, and if I use QueryOver<> it return
>>> false ???
>>>
>>> I don't really understand how it all works but I've noticed the
>>> following.
>>> when its called using Query<> selection.firstrow = -1, and
>>> selection.MaxRows = 1
>>>
>>> but when its called from QueryOver<> selection.FirstRow = 0, and
>>> selection.Maxrows = -1
>>>
>>>
>>>
>>>
>>> Andrew
>>>
>>>
>>> On Jul 5, 12:38 pm, Fabio Maulo <[email protected]> wrote:
>>> > Confirmed, we have a bug.
>>> > We are changing the meaning of Single.
>>> >
>>> >
>>> >
>>> > On Mon, Jul 5, 2010 at 8:35 AM, Fabio Maulo <[email protected]>
>>> wrote:
>>> > > If our provider creates a paginated query for the method "Single" we
>>> have a
>>> > > bug.
>>> >
>>> > > On Mon, Jul 5, 2010 at 8:06 AM, andrew6072 <
>>> [email protected]>wrote:
>>> >
>>> > >> Hi Fabio,
>>> >
>>> > >> I think the exception got chopped off, this is the full exception.
>>> >
>>> > >> [SQL: select * from ( select olauser0_.USER_ID as USER1_57_,
>>> > >> olauser0_.USERNAME as USERNAME57_, olauser0_.EMAIL_ADDRESS as
>>> > >> EMAIL3_57_, olauser0_.COMMENTS as COMMENTS57_, olauser0_.PASSWORD as
>>> > >> PASSWORD57_, olauser0_.PASSWORD_QUESTION as PASSWORD6_57_,
>>> > >> olauser0_.PASSWORD_ANSWER as PASSWORD7_57_, olauser0_.IS_APPROVED as
>>> > >> IS8_57_, olauser0_.IS_LOCKEDOUT as IS9_57_,
>>> olauser0_.LAST_LOGON_DATE
>>> > >> as LAST10_57_, olauser0_.CREATION_DATE as CREATION11_57_,
>>> > >> olauser0_.LAST_ACTIVITY_DATE as LAST12_57_,
>>> > >> olauser0_.LAST_PASSWORD_CHANGED_DATE as LAST13_57_,
>>> > >> olauser0_.LAST_LOCKOUT_DATE as LAST14_57_ from OLA_USERS olauser0_
>>> > >> where (olauser0_.USERNAME is null) and (:p0 is null) or
>>> > >> olauser0_.USERNAME=:p0 ) where rownum <=:p2] --->
>>> > >> Oracle.DataAccess.Client.OracleException ORA-01008: not all
>>> variables
>>> > >> bound    at
>>> > >> Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32
>>> > >> errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx*
>>> > >> pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
>>> > >>   at Oracle.DataAccess.Client.OracleException.HandleError(Int32
>>> > >> errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx,
>>> > >> OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
>>> > >>   at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean
>>> > >> requery, Boolean fillRequest, CommandBehavior behavior)
>>> > >>   at
>>> > >>
>>> Oracle.DataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior
>>> > >> behavior)
>>> > >>   at
>>> > >> System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
>>> > >>   at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
>>> > >> in
>>> d:\dev\oss\nhibernate\src\NHibernate\AdoNet\AbstractBatcher.cs:line
>>> > >> 242
>>> > >>   at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean
>>> > >> autoDiscoverTypes, Boolean callable, RowSelection selection,
>>> > >> ISessionImplementor session) in d:\dev\oss\nhibernate\src\NHibernate
>>> > >> \Loader\Loader.cs:line 1325
>>> > >>   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
>>> > >> QueryParameters queryParameters, Boolean returnProxies) in
>>> d:\dev\oss
>>> > >> \nhibernate\src\NHibernate\Loader\Loader.cs:line 401
>>> > >>   at
>>> >
>>> > >>
>>> NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImp­lementor
>>> > >> session, QueryParameters queryParameters, Boolean returnProxies) in
>>> d:
>>> > >> \dev\oss\nhibernate\src\NHibernate\Loader\Loader.cs:line 236
>>> > >>   at NHibernate.Loader.Loader.DoList(ISessionImplementor session,
>>> > >> QueryParameters queryParameters) in d:\dev\oss\nhibernate\src
>>> > >> \NHibernate\Loader\Loader.cs:line 1653
>>> > >>    --- End of inner exception stack trace ---
>>> > >>    at NHibernate.Loader.Loader.DoList(ISessionImplementor session,
>>> > >> QueryParameters queryParameters) in d:\dev\oss\nhibernate\src
>>> > >> \NHibernate\Loader\Loader.cs:line 1662
>>> > >>   at
>>> > >> NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor
>>> > >> session, QueryParameters queryParameters) in
>>> d:\dev\oss\nhibernate\src
>>> > >> \NHibernate\Loader\Loader.cs:line 1577
>>> > >>   at NHibernate.Loader.Loader.List(ISessionImplementor session,
>>> > >> QueryParameters queryParameters, ISet`1 querySpaces, IType[]
>>> > >> resultTypes) in d:\dev\oss\nhibernate\src\NHibernate\Loader
>>> > >> \Loader.cs:line 1567
>>> > >>   at
>>> > >> NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor
>>> > >> session, QueryParameters queryParameters) in
>>> d:\dev\oss\nhibernate\src
>>> > >> \NHibernate\Hql\Ast\ANTLR\Loader\QueryLoader.cs:line 297
>>> > >>   at
>>> > >>
>>> NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor
>>> > >> session, QueryParameters queryParameters) in
>>> d:\dev\oss\nhibernate\src
>>> > >> \NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs:line 107
>>> > >>   at
>>> NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters
>>> > >> queryParameters, ISessionImplementor session, IList results) in
>>> d:\dev
>>> > >> \oss\nhibernate\src\NHibernate\Engine\Query\HQLQueryPlan.cs:line 105
>>> > >>   at NHibernate.Impl.SessionImpl.List(IQueryExpression
>>> > >> queryExpression, QueryParameters queryParameters, IList results) in
>>> d:
>>> > >> \dev\oss\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 676
>>> > >>   at NHibernate.Impl.SessionImpl.List(IQueryExpression
>>> > >> queryExpression, QueryParameters parameters) in
>>> d:\dev\oss\nhibernate
>>> > >> \src\NHibernate\Impl\SessionImpl.cs:line 655
>>> > >>   at NHibernate.Impl.ExpressionQueryImpl.List() in d:\dev\oss
>>> > >> \nhibernate\src\NHibernate\Impl\ExpressionQueryImpl.cs:line 63
>>> > >>   at NHibernate.Linq.NhQueryProvider.Execute(Expression expression)
>>> > >> in d:\dev\oss\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line
>>> > >> 31
>>> > >>   at NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression
>>> > >> expression) in d:\dev\oss\nhibernate\src\NHibernate\Linq
>>> > >> \NhQueryProvider.cs:line 55
>>> > >>   at System.Linq.Queryable.Single[TSource](IQueryable`1 source)
>>> > >>   at
>>> > >>
>>> OlaCommon.Data.Repository.NHibernate.UserRepository.GetByUsername(String
>>> > >> username) in
>>> d:\dev\tfs\OlaCommon\OlaCommon.Data\Repository\NHibernate
>>> > >> \UserRepository.cs:line 27
>>> > >>   at
>>> > >>
>>> OlaMonitor.Infrastructure.NHibernateMembershipProvider.ValidateUser(String
>>> > >> username, String password) in d:\dev\tfs\OlaMonitor\OlaMonitor
>>> > >> \Infrastructure\NHibernateMembershipProvider.cs:line 248
>>> >
>>> > >> Validateuser calls the following method
>>> > >>        public OlaUser GetByUsername(string username)
>>> > >>        {
>>> > >>            var session = GetSession();
>>> > >>             var query = (from a in session.Query<OlaUser>()
>>> > >>                              where a.Username == username
>>> > >>                             select a);
>>> > >>            var user = query.Single();
>>> > >>             return user;
>>> > >>        }
>>> >
>>> > >> Do you need anything else ?
>>> >
>>> > >> Andrew
>>> >
>>> > >> On Jul 5, 11:43 am, Fabio Maulo <[email protected]> wrote:
>>> > >> > Please send us something else... In some point you are forcing the
>>> > >> > pagination of the query.
>>> >
>>> > >> > --
>>> > >> > Fabio Maulo
>>> >
>>> > >> > El 05/07/2010, a las 07:16, andrew6072 <
>>> [email protected]>
>>> > >> escribió:
>>> >
>>> > >> > > Hi,
>>> >
>>> > >> > > Not sure if I've done something wrong but I can't get this to
>>> work, if
>>> > >> > > I look at the query I can see one object, as soon as it hits the
>>> > >> > > query.single() it bombs with the stack below, am I missing
>>> something ?
>>> > >> > > Not sure if it makes any difference but I'm using fluent to
>>> create my
>>> > >> > > mappings.
>>> >
>>> > >> > >            var query = (from a in session.Query<OlaUser>()
>>> > >> > >                       where a.Username == username
>>> > >> > >                       select a);
>>> >
>>> > >> > >            var user = query.Single();
>>> >
>>> > >> > > Andrew
>>> >
>>> > >> > > [ select * from ( select olauser0_.USER_ID as USER1_57_,
>>> > >> > > olauser0_.USERNAME as USERNAME57_, olauser0_.EMAIL_ADDRESS as
>>> > >> > > EMAIL3_57_, olauser0_.COMMENTS as COMMENTS57_,
>>> olauser0_.PASSWORD as
>>> > >> > > PASSWORD57_, olauser0_.PASSWORD_QUESTION as PASSWORD6_57_,
>>> > >> > > olauser0_.PASSWORD_ANSWER as PASSWORD7_57_,
>>> olauser0_.IS_APPROVED as
>>> > >> > > IS8_57_, olauser0_.IS_LOCKEDOUT as IS9_57_,
>>> olauser0_.LAST_LOGON_DATE
>>> > >> > > as LAST10_57_, olauser0_.CREATION_DATE as CREATION11_57_,
>>> > >> > > olauser0_.LAST_ACTIVITY_DATE as LAST12_57_,
>>> > >> > > olauser0_.LAST_PASSWORD_CHANGED_DATE as LAST13_57_,
>>> > >> > > olauser0_.LAST_LOCKOUT_DATE as LAST14_57_ from USERS olauser0_
>>> where
>>> > >> > > (olauser0_.USERNAME is null) and (:p0 is null) or
>>> > >> > > olauser0_.USERNAME=:p0 ) where rownum <=:p2 ]
>>> > >> > >  Name:p1 - Value:andrewb
>>> >
>>> > >> > > Oracle.DataAccess.Client.OracleException ORA-01008: not all
>>> variables
>>> > >> > > bound    at
>>> > >> > > Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32
>>> > >> > > errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx*
>>> > >> > > pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
>>> > >> > >   at Oracle.DataAccess.Client.OracleException.HandleError(Int32
>>> > >> > > errCode, OracleConnection conn, String procedure, IntPtr
>>> opsErrCtx,
>>> > >> > > OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
>>> > >> > >   at
>>> Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean
>>> > >> > > requery, Boolean fillRequest, CommandBehavior behavior)
>>> > >> > >   at
>>> >
>>> > >>
>>> Oracle.DataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior
>>> > >> > > behavior)
>>> > >> > >   at
>>> > >> > >
>>> System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
>>> > >> > >   at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand
>>> cmd)
>>> > >> > > in
>>> d:\dev\oss\nhibernate\src\NHibernate\AdoNet\AbstractBatcher.cs:line
>>> > >> > > 242
>>> > >> > >   at NHibernate.Loader.Loader.GetResultSet(IDbCommand st,
>>> Boolean
>>> > >> > > autoDiscoverTypes, Boolean callable, RowSelection selection,
>>> > >> > > ISessionImplementor session) in
>>> d:\dev\oss\nhibernate\src\NHibernate
>>> > >> > > \Loader\Loader.cs:line 1325
>>> > >> > >   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor
>>> session,
>>> > >> > > QueryParameters queryParameters, Boolean returnProxies) in
>>> d:\dev\oss
>>> > >> > > \nhibernate\src\NHibernate\Loader\Loader.cs:line 401
>>> > >> > >   at
>>> >
>>> > >>
>>> NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImp­­lementor
>>> > >> > > session, QueryParameters queryParameters, Boolean returnProxies)
>>> in d:
>>> > >> > > \dev\oss\nhibernate\src\NHibernate\Loader\Loader.cs:line 236
>>> > >> > >   at NHibernate.Loader.Loader.DoList(ISessionImplementor
>>> session,
>>> > >> > > QueryParameters queryParameters) in d:\dev\oss\nhibernate\src
>>> > >> > > \NHibernate\Loader\Loader.cs:line 1653
>>> > >> > > 2010-07-05 10:54:20,134 [9] WARN
>>>  NHibernate.Util.ADOExceptionReporter
>>> > >> > > - Oracle.DataAccess.Client.OracleException ORA-01008: not all
>>> > >> > > variables bound    at
>>> > >> > > Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32
>>> > >> > > errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx*
>>> > >> > > pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
>>> >
>>> > ...
>>> >
>>> > read more »- Hide quoted text -
>>> >
>>> > - Show quoted text -
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "nhusers" group.
>>> To post to this group, send email to <[email protected]>
>>> [email protected].
>>> To unsubscribe from this group, send email to
>>> <nhusers%[email protected]>
>>> [email protected].
>>> For more options, visit this group at
>>> <http://groups.google.com/group/nhusers?hl=en>
>>> http://groups.google.com/group/nhusers?hl=en.
>>>
>>>
>>
>>
>> --
>> Fabio Maulo
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To post to this group, send email to <[email protected]>
>> [email protected].
>> To unsubscribe from this group, send email to
>> <nhusers%[email protected]>
>> [email protected].
>> For more options, visit this group at
>> <http://groups.google.com/group/nhusers?hl=en>
>> http://groups.google.com/group/nhusers?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>

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

Reply via email to