I have a SELECT statement that returns row_number() value with all other fields from table. Query is pretty simple and is working in SSMS:
SELECT
*, CAST(ROW_NUMBER() OVER(ORDER BY TablePrimaryKey) AS INT) AS [RowNumber]
FROM
TableName
WHERE
TablePrimaryKey > 10
(In real application WHERE
statement is much more complex, but for simplicity I put it like this)
In my project I created a POCO class that contains RowNumber
property (with all other necessary properties)
...
public int RowNumber { get; set; }
...
And I made sure migrations won't create additional columns in table at my entityConfiguration
class:
this.Ignore(x => x.RowNumber);
Problem is that with Entity Framework's SqlQuery()
method it returns all columns from the table as it should, but RowNumber
is always 0. I'm using Entity Framework 6.1 version. Did I miss something, or can this not be done this way?