I posted this on the Entity Framework/ADO.Net forum as well since I think it's an EF problem and not DevForce but just in case it is or someone has seen this before, I'm posting it here as well.
Entity Framework (.Net 3.5/Visual Studio 2008 SP1/SQL Server 2008) using DevForce RTW with Silverlight 3 using a PassThruESQLQuery.
I have an entity that has one key column (GUID) and a single scalar column (BIGINT) that have been mapped in the model from the database (nothing behind the scenes here). If I create an ESQL query like:
SELECT VALUE u FROM myEntitySet as u
the query result can be cast to the entity type correctly. If however, I specify the column names:
SELECT u.myKey, u.myCounter FROM myEntitySet as u
then the query is physically executed (I can see it in SQL Profiler) but Entity Framework throws this error:
The specified cast from a materialized 'System.Data.Objects.MaterializedDataRecord' type to the 'MyTestProject.myEntity' type is not valid.
at System.Data.Common.Internal.Materialization.Translator.CheckedConvert[TSource,TTarget](TSource value)
I've tried switching the order of the columns around; adding an "as" clause (u.myKey AS myKey); using VALUE ROW or just ROW but the issue persists. When I look at the generated T-SQL, I notice that a "SELECT 1 AS [C1]" is added to the ESQL query that specifies the columns so my result set ends up having three columns instead of two. I think this is confusing conversion from datarecord to entity:
SELECT
1 AS [C1],
[Extent1].[my_key] AS [my_key],
[Extent1].[totalCount] AS [totalCount]
FROM [dbo].[myEntity] AS [Extent1]
If I just use SELECT VALUE u, it generates:
SELECT
[Extent1].[my_key] AS [my_key],
[Extent1].[totalCount] AS [totalCount]
FROM [dbo].[myEntity] AS [Extent1]
Any help would be appreciated.