此声明中的关键字“值”是什么意思,我可以去哪里了解更多信息?
如果我省略关键字“value”会发生什么?在下面的代码中,z 是一个 Entity Framework 类。
string queryString = "SELECT VALUE q from x.zs as q where q.a = @parm;"
ObjectQuery<z> query = context.CreateQuery<z>
(queryString, new ObjectParameter("parmname",parmvalue));
return query.First();
(这是考试练习题的一部分)。
上面的代码在一个返回 z 类型变量的函数中。
最佳答案
即 Entity SQL句法。 Value
关键字只允许指定一个值,并且不添加行包装器。
阅读 article about SELECT statement in ESQL
Entity SQL supports two variants of the SELECT clause. The first variant, row select, is identified by the SELECT keyword, and can be used to specify one or more values that should be projected out. Because a row wrapper is implicitly added around the values returned, the result of the query expression is always a multiset of rows.
Each query expression in a row select must specify an alias. If no alias is specified,Entity SQL attempts to generate an alias by using the alias generation rules.
The other variant of the SELECT clause, value select, is identified by the SELECT VALUE keyword. It allows only one value to be specified, and does not add a row wrapper.
所以,如果你想实现
z
您查询中的对象,您应该使用 SELECT VALUE
语法(否则你会得到异常:从 MaterializedDataRecord 转换到 z 类型是无效的)。无
VALUE
关键字您将获得一组行:string esql = "SELECT q from x.zs as q where q.a = @parm;";
ObjectQuery<DbDataRecord> query = context
.CreateQuery<DbDataRecord>(esql, new ObjectParameter("parm",parmvalue));
var result = query.First();
关于linq - "SELECT VALUE"- LINQ/ Entity Framework 查询中的值关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15386766/