c# - Entity Framework SqlQuery not returning row_number() value -
c# - Entity Framework SqlQuery not returning row_number() value -
i have select statement returns row_number() value other fields table. query pretty simple , working in ssms:
select *, cast(row_number() over(order tableprimarykey) int) [rownumber] tablename tableprimarykey > 10
(in real application where
statement much more complex, simplicity set this)
in project created poco class contains rownumber
property (with other necessary properties)
... public int rownumber { get; set; } ...
and made sure migrations won't create additional columns in table @ entityconfiguration
class:
this.ignore(x => x.rownumber);
problem entity framework's sqlquery()
method returns columns table should, rownumber
0. i'm using entity framework 6.1 version. did miss something, or can not done way?
this reply question in comment.
with main ( select * ,row_number() over(order primarykeyid) 'rownumber' [tablename] [month] = 10 , [year] = 2014 ) select * main rownumber = 2
c#/ef code:
int rownumber = 2; var row = tablename.orderby(t=>t.primarykeyid).skip(rownumber -1).take(1);
the sql generated looks like:
declare @p0 int = 1 declare @p1 int = 1 select [t1].[id], [t1].c1 ( select row_number() on (order [t0].[id]) [row_number], [t0].[id], [t0].c1 [tablename] [t0] ) [t1] [t1].[row_number] between @p0 + 1 , @p0 + @p1 order [t1].[row_number]
i using linq-to-sql, ef should similar: sorting on server side, , returns 1 record only.
c# entity-framework
Comments
Post a Comment