German
German

Reputation: 740

Rewrite SQL query using Linq to entity

Hi guys I need to rewrite the sql query below using Linq to entity. Unfortunately I don't have a lot of experience of using Linq. Please help me

 With TempTableName AS 
(SELECT [ColumnName],  
        [ColumnName2], 
        [ColumnName3], 
        [ColumnName4], 
 ROW_NUMBER() OVER (order by ColumnName desc) as RowNumber from TableName )
         SELECT 
        [ColumnName],  
        [ColumnName2], 
        [ColumnName3], 
        [ColumnName4]
FROM TempTableName  WHERE ROWNUMBER 
Between 10 and 100 

Upvotes: 1

Views: 166

Answers (1)

GvS
GvS

Reputation: 52518

(from t in dbContext.TableName
order by ColumnName descending
select new { ColumnName = t.ColumnName, ColumnName2 = t.ColumnName2 /* ... */  })
.Skip(9)
.Take(91)

If you want to work all the columns from TableName, you can also use select t, this. Probably easier to use, but this will fetch all columns, and it is not clear from your question if that is what you want.

Upvotes: 3

Related Questions