Jump to content

Exception of type 'Antlr.Runtime.NoViableAltException' was thrown


mikev1976

Recommended Posts

I am trying to send a query in VS 2010 for our web application: var firstHraIdFromCallAppointment = _session.Query<ICallAppointment>().Select(x => x.Callee.HealthAssessments.Any(hra => hra.CompletedDate != null) ? x.Callee.HealthAssessments.Where(hra => hra.CompletedDate != null).OrderByDescending(hra => hra.CompletedDate).FirstOrDefault().Id : Guid.Empty).FirstOrDefault() ; I can't see anything wrong with the query. But it gives me the following error: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. [.First[system.Guid](.Select[HealthTools.Core.Domain.Model.Outreach.ICallAppointment,System.Guid](NHibernate.Linq.NhQueryable`1[HealthTools.Core.Domain.Model.Outreach.ICallAppointment], Quote((x, ) => (.Any[HealthTools.Core.Domain.HealthAssessment.Entities.HRA](x.Callee.HealthAssessments, (hra, ) => (DateTime.op_Inequality(hra.CompletedDate, NULLp1)), ) ? .First[HealthTools.Core.Domain.HealthAssessment.Entities.HRA](.OrderByDescending[HealthTools.Core.Domain.HealthAssessment.Entities.HRA,System.Nullable`1[[system.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]](.Where[HealthTools.Core.Domain.HealthAssessment.Entities.HRA](x.Callee.HealthAssessments, (hra, ) => (DateTime.op_Inequality(hra.CompletedDate, NULLp3)), ), (hra, ) => (hra.CompletedDate), ), ).Id : p2)), ), )] Any clues as to why or where to start?

Link to comment
Share on other sites

I run SQL Server Profiler. I think this is the query that is failing: exec sp_executesql N'select TOP (@p0) icallappoi0_.CallAppointmentId as col_0_0_, icallappoi0_.StartDate as col_1_0_, icallappoi0_.CallAppointmentStatusTypeId as col_2_0_,user3_.UserId as col_3_0_, sponsor5_.SponsorId as col_4_0_, user3_.NameFirst as col_5_0_, user3_.NameLast as col_6_0_,select cast(count(*) as INT)from [HealthTools].Outreach_Core.Calls calls9_whereicallappoi0_.CallAppointmentId=calls9_.CallAppointmentId) as col_7_0_, user4_.UserId as col_8_0_, user4_.NameFirst as col_9_0_,user4_.NameLast as col_10_0_, sponsor5_.SponsorCode as col_11_0_, timezones8_.TimeZoneId as col_12_0_, timezones8_.Abbreviation as col_13_0_,case when icallappoi0_.CallAppointmentTypeId=1 then 1 else 0 end as col_14_0_, sponsor5_.SponsorId as col_15_0_, icallappoi0_.CreatedDate as col_16_0_,(select cast(max(calls10_.CallDate) as DATETIME) from [HealthTools].Outreach_Core.Calls calls10_ where icallappoi0_.CallAppointmentId=calls10_.CallAppointmentId) as col_17_0_,icallappoi0_.RiskTypeId as col_18_0_, sponsor5_.SponsorId as SponsorId51_0_, sponsor5_.SponsorId as SponsorId51_1_, sponsor5_.DatafeedPassword as Datafeed2_51_0_,sponsor5_.SponsorCode as SponsorC3_51_0_, sponsor5_.Name as Name51_0_, sponsor5_.LessonResetDate as LessonRe5_51_0_, sponsor5_.CreatedDate as CreatedD6_51_0_,sponsor5_.ParentId as ParentId51_0_, sponsor5_.DatafeedPassword as Datafeed2_51_1_, sponsor5_.SponsorCode as SponsorC3_51_1_, sponsor5_.Name as Name51_1_,sponsor5_.LessonResetDate as LessonRe5_51_1_, sponsor5_.CreatedDate as CreatedD6_51_1_, sponsor5_.ParentId as ParentId51_1_from [HealthTools].Outreach_Core.CallAppointments icallappoi0_left outer join [HealthTools].Member.Users user1_ on icallappoi0_.CalleeId=user1_.UserIdleft outer join [HealthTools].Member.Users user2_ on icallappoi0_.CalleeId=user2_.UserIdleft outer join [HealthTools].Member.Users user3_ on icallappoi0_.AssignedCallerId=user3_.UserIdleft outer join [HealthTools].Member.Users user4_ on icallappoi0_.CalleeId=user4_.UserIdleft outer join [HealthTools].Sponsor.Sponsors sponsor5_ on user4_.SponsorId=sponsor5_.SponsorIdleft outer join [HealthTools].Member.TimeZones timezones8_ on user4_.TimeZone=timezones8_.TimeZoneIdwhere icallappoi0_.CallAppointmentStatusTypeId=@p1order by user1_.NameLast asc, user2_.NameFirst asc',N'@p0 int,@p1 int',@p0=15,@p1=1 It tells me: Msg 156, Level 15, State 1, Line 4Incorrect syntax near the keyword 'select'.Msg 102, Level 15, State 1, Line 7Incorrect syntax near ')'.Msg 156, Level 15, State 1, Line 10Incorrect syntax near the keyword 'as'.

Link to comment
Share on other sites

The problem seems to be near the beginning: select cast(count(*) as INT) I change it to (select cast(count(*) as INT) and the query runs. Now the next question is what do I change to get that ( to show up when VS used Nhibernate to build the query?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...