I've been working with EF4/Stored Procedures/Complex Types for a while now, but i haven't seen this issue before.
I have a stored proc which returns a bunch of fields, mapped to a collection of complex types. Was all working fine until i introduced this extra field.
It's using ROW_NUMBER from T-SQL (used in ranking results):
SELECT ...
ROW_NUMBER() OVER (ORDER BY [Field1], [Field2]) AS [SearchRank],
...
FROM @ResultSet
In my complex type, i have this set as a non-nullable Int32, and i'm also using POCO's, so i have this as a regular int on the POCO.
But when i try and execute the query, i get this error:
System.InvalidOperationException: The 'SearchRank' property on 'RankedLocationSearchResult' could not be set to a 'Int64' value. You must set this property to a non-null value of type 'Int32'.
I just don't get it. Nowhere have i said this property/field is Int64. And my property is a non-null value of type 'Int32'.
Now, i am certain the problem is with ROW_NUMBER().
Because if i change that T-SQL to just 1 AS [SearchRank] (hard code, for testing), it works fine.
It's almost as like EF sees ROW_NUMBER() as returning Int64.
Why? Do we have to cast this as a 32-bit integer or something?
Anyone had this issue?