sql - Entity Framework v5.0 Exception 'From' is a reserved keyword and cannot be used as an alias, unless it is escaped -
i use entityframework v5.0, entitydatasource control.
in code set sql query, when open page after compilation exception. how can fix it?
code:
entrylistds.commandparameters.add(new parameter("subid", dbtype.int32, common.currentuserid.tostring())); entrylistds.commandparameters.add(new parameter("typeid", dbtype.int32, ((int)messagetype.wall).tostring())); entrylistds.commandtext = @"select m.id, m.to, m.subject, m.bodyhtml, m.creationdate, m.new, m.typeid message m join subscription s on m.from = s.objectid s.subscriberid = @subid , m.typeid = @typeid order m.creationdate desc";
exeption when open page:
'from' reserved keyword , cannot used alias, unless escaped. near line 12, column 6.
description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code. exception details: system.data.entitysqlexception: 'from' reserved keyword , cannot used alias, unless escaped. near line 12, column 6. source error: unhandled exception generated during execution of current web request. information regarding origin , location of exception can identified using exception stack trace below. stack trace: [entitysqlexception: 'from' reserved keyword , cannot used alias, unless escaped. near line 12, column 6.] system.data.common.entitysql.cqllexer.mapunescapedidentifier(string symbol) +8073331 system.data.common.entitysql.cqllexer.mapidentifierorkeyword(string symbol) +57 system.data.common.entitysql.cqllexer.accept_83() +36 system.data.common.entitysql.cqllexer.yylex() +386 system.data.common.entitysql.cqlparser.yylex() +16 system.data.common.entitysql.cqlparser.yyparse() +132 system.data.common.entitysql.cqlparser.internalparseentrypoint() +101 system.data.common.entitysql.cqlparser.parse(string query) +148 system.data.common.entitysql.cqlquery.parse(string commandtext, parseroptions parseroptions) +41 system.data.common.entitysql.cqlquery.compilecommon(string commandtext, perspective perspective, parseroptions parseroptions, func`3 compilationfunction) +84 system.data.common.entitysql.cqlquery.compilequerycommandlambda(string querycommandtext, perspective perspective, parseroptions parseroptions, ienumerable`1 parameters, ienumerable`1 variables) +100 system.data.objects.entitysqlquerystate.parse() +8608663 system.data.objects.entitysqlquerystate.getresulttype() +4 system.data.objects.objectquery.getresulttype() +58 system.web.ui.webcontrols.entitydatasourcequerybuilder`1.buildbasicquery(objectcontext context, boolean computecount) +108 system.web.ui.webcontrols.entitydatasourceview.executeselecttyped(datasourceselectarguments arguments, creator qbconstructor) +355 system.web.ui.webcontrols.entitydatasourceview.executeselect(datasourceselectarguments arguments) +606 system.web.ui.datasourceview.select(datasourceselectarguments arguments, datasourceviewselectcallback callback) +21 system.web.ui.webcontrols.databoundcontrol.performselect() +138 system.web.ui.webcontrols.listview.performselect() +102 system.web.ui.webcontrols.basedataboundcontrol.databind() +30 system.web.ui.webcontrols.basedataboundcontrol.ensuredatabound() +105 system.web.ui.webcontrols.listview.createchildcontrols() +52 system.web.ui.control.ensurechildcontrols() +83 system.web.ui.control.prerenderrecursiveinternal() +42 system.web.ui.control.prerenderrecursiveinternal() +168 system.web.ui.control.prerenderrecursiveinternal() +168 system.web.ui.control.prerenderrecursiveinternal() +168 system.web.ui.control.prerenderrecursiveinternal() +168 system.web.ui.control.prerenderrecursiveinternal() +168 system.web.ui.control.prerenderrecursiveinternal() +168 system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) +974 version information: microsoft .net framework version:4.0.30319; asp.net version:4.0.30319.18033
if use keywords or special symbols in column names, brackets required. put column name in square brackets:
on m.[from] = s.objectid
Comments
Post a Comment