Finally this endedup being a problem within NH itself. I investigated it a bit further and found it was related to using use_sql_comments=true, which caused MSSQL200xDialect to incorrectly process the statement.
I created a bug with a unit test at nh-jira, which can be found here: http://nhjira.koah.net/browse/NH-1858 On Fri, Jun 26, 2009 at 5:04 PM, Pci <[email protected]> wrote: > > Hi, > > I'm using NH.Linq trunk with NH 2.1Beta2, and I'm having a problem > with this query: > > ret = ses.Linq<UserCredentials>() > .Where(x => x.User == user > && x.IdentityProvider == > provider > && x.Username == identifier > ) > .SingleOrDefault(); > > This throws the following exception: > > [SQL: top 2/* criteria query */ SELECT this_.Id as Id4_2_, > this_.Username as Username4_2_, this_.Password as Password4_2_, > this_.UserUniqueId as UserUniq4_4_2_, this_.IdentityProviderUniqueId > as Identity5_4_2_, user1_.UniqueId as UniqueId0_0_, user1_.Timestamp > as Timestamp0_0_, user1_.Created as Created0_0_, user1_.Name as > Name0_0_, user1_.LastName as LastName0_0_, user1_.Email as Email0_0_, > user1_.Disabled as Disabled0_0_, user1_.DisabledSince as > Disabled8_0_0_, user1_.IsSystemManager as IsSystem9_0_0_, > user1_.LastAccess as LastAccess0_0_, identitypr2_.UniqueId as > UniqueId1_1_, identitypr2_.Timestamp as Timestamp1_1_, > identitypr2_.IdentityClaimType as Identity4_1_1_, > identitypr2_.IdentityClaimValue as Identity5_1_1_, > identitypr2_.Created as Created1_1_, identitypr2_.Name as Name1_1_, > identitypr2_.Type as Type1_1_, identitypr2_.IsDefault as > IsDefault1_1_, identitypr2_.UserIdentityClaimType as UserIden9_1_1_ > FROM UserCredentials this_ left outer join Users user1_ on > this_.UserUniqueId=user1_.UniqueId left outer join IdentityProviders > identitypr2_ on this_.IdentityProviderUniqueId=identitypr2_.UniqueId > WHERE ((user1_.UniqueId = @p0 and this_.IdentityProviderUniqueId = > @p1) and this_.Username = @p2)] ---> > System.Data.SqlClient.SqlException: Incorrect syntax near the keyword > 'top' > > As you can see, seems like NH.Linq (or NH) is building an invalid > query by placing "TOP 2" clause at the beginning.. I have "lots" of > queries using SingleOrDefault working w7o problem, so, looks like its > something related to this one.. > > As the code surrounding all this it's a bit complex, I'll try to > narrow the problem down a little bit in order to provide a unit test, > but meanwhile.. Did any of you experience something similar? > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "NHibernate Contrib - Development Group" 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.ar/group/nhcdevs?hl=en -~----------~----~----~----~------~----~------~--~---
