views:

52

answers:

1

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 
+2  A: 
(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.

GvS
this works for me. Thank you for quick and working answer
German