Question

I am using EF4.0 to do in my mind a very basic query. I have confirmed that all columns reference in my tables are Int (we don't use bigint nor smallint) so I ruled that out. I have tried changing the types to Int64 which it then complains about casting to Int32. This leads me to believe the "issue is not the issue" type scenario. What is the EF system complaining about?

public class clsResult
{
    public Int32 PkId { get; set; }
    public Int32 FkId { get; set; }
    public Int32 Threshold { get; set; }
}

var qry = db.ExecuteStoreQuery<clsResult>(@"SELECT PkId, FkId, Threshold
                                        FROM (SELECT ROW_NUMBER() OVER (PARTITION BY FkId ORDER BY PkId ASC) AS Threshold, *
                                              FROM ClientTrans
                                        ) AS T1
                                        WHERE (Threshold <= 3)
                                        AND (ClientID IN (  SELECT Id 
                                                            FROM ClientProfile
                                                            WHERE (p.Login LIKE 'WEBS%')))
                                        AND (DateRpt >= @STARTDATE)
                                        AND (DateRpt <= @ENDDATE)", SqlParams).ToList();

Error Produced: The specified cast from a materialized 'System.Int64' type to the 'System.Int32' type is not valid.

Was it helpful?

Solution

As per documentation, return type of row_number() is bigint.

Therefore, you should only change type of Threshold.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top