"SELECT VALUE" - value keyword in LINQ / Entity Framework query

What does the keyword β€œmeaning” mean in this statement, and where will I go to find out more?
What happens if I leave the keyword "meaning"? In the code below, z is the entity infrastructure class.

string queryString = "SELECT VALUE q from x.zs as q where qa = @parm;" ObjectQuery<z> query = context.CreateQuery<z> (queryString, new ObjectParameter("parmname",parmvalue)); return query.First(); 

(This is part of the practical question for the exam).

The above code is in a function that returns a variable of type z.

+23
linq linq-to-entities entity-framework
Mar 13 '13 at 13:30
source share
1 answer

This is the Entity SQL Syntax . The Value keyword allows you to specify only one value and not add a wrapper to the string.

Read the article on SELECT statements in ESQL

Entity SQL supports two variations of the SELECT clause. The first option, row selection, is determined by the SELECT keyword and can be used to indicate one or more values ​​to be projected. Because string wrappers are implicitly added around return values, the result of a query expression is always a plurality of strings.

Each query expression in the select string must specify an alias. If no alias is specified, Entity SQL attempts to generate an alias using the alias generation rules.

Another variant of the SELECT clause, the choice of value, is determined by the SELECT VALUE keyword. It allows you to specify only one value, and does not add a wrapper for strings.

So, if you want to materialize the z object from your query, you must use the SELECT VALUE syntax (otherwise you will get an exception: cast from MaterializedDataRecord to z type is not valid).

Without the Value keyword, you get a rowset:

 string esql = "SELECT q from x.zs as q where qa = @parm;"; ObjectQuery<DbDataRecord> query = context .CreateQuery<DbDataRecord>(esql, new ObjectParameter("parm",parmvalue)); var result = query.First(); 
+30
Mar 13 '13 at 13:35
source share



All Articles