2010-09-26 3 views
5
return NHibernateSession.CreateQuery(@"TRUNCATE TABLE dbo.Exceptions").ExecuteUpdate(); 

Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. [TRUNCATE TABLE Exceptions] Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.nhibernate Antlr.Runtime.NoViableAltException

Exception Details: NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. [TRUNCATE TABLE Exceptions]

Source Error:

eine Idee, warum?

Antwort

18

TRUNCATE TABLE ist keine gültige HQL-Anweisung.

Verwenden Sie CreateSQLQuery anstelle von CreateQuery, um SQL-Anweisungen auszuführen.

+2

Ja, das ist die richtige Antwort. –

+0

Danke für Hilfe Diego. – senzacionale

+0

Off topic: Warum setzt NHibernate eine ANTLR-Ausnahme frei? Wie soll der Benutzer damit umgehen? Sollte es nicht eine InvalidQuerySyntaxException oder whatnot werfen? –