1

I'm getting data out of my object context using .CreateQuery(sqlStatement, parameterValues). Please note that this the Entity SQL that I am using as a string constant being passed into the CreateQuery method, not a compiled LINQ query in my source code.

This works perfectly. However there are some duplicate records...

ctx.CreateQuery<DbDataRecord>(@"SELECT  record.home_city, record.home_stabb 
FROM Employees AS record  
ORDER BY record.home_city SKIP 0 LIMIT 15",prms);

So I thought this would remove the duplicates:

ctx.CreateQuery<DbDataRecord>(@"SELECT DISTINCT record.home_city, record.home_stabb 
FROM Employees AS record  
ORDER BY record.home_city SKIP 0 LIMIT 15",prms);

Exact same statement, exact same object context. However, when I add in the DISTINCT Modifier, I get the exception below. I know all of the columns are correct because the first statement works perfectly. Jusjing by the exception, it appears to have a problem with the ORDER BY clause.

Is there something that I'm missing? This makes no sense to me.

System.Data.EntitySqlException was unhandled by user code
Message='record.home_city' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near member access expression, line 1, column 95.
Source=System.Data.Entity
Column=95
ErrorContext=member access expression, line 1, column 95
4

1 回答 1

0

你可以在下面尝试,然后再运行一个不同的?我知道不同是您面临此问题的主要原因,但至少您知道另一种解决方法。

ctx.CreateQuery<DbDataRecord>(@"SELECT VALUE record FROM Employees AS record  
ORDER BY record.home_city SKIP 0 LIMIT 15",prms);
于 2013-08-27T07:13:55.553 回答