I am using Web Api with OData. and I have an entity defined in an EF 5.0.
I am sending very simple request to Controller::
$.ajax({url: "/odata/Details?$top=10",
type: "GET",
dataType: 'json',
success: function (data) {
viewModel.list(data.value);
}
Now code on My controller::
[Queryable]
public override IQueryable<Area> Get()
{
return db.Area.AsQueryable();
}
Query i see using SQL Profiler::
SELECT TOP (@p__linq__1)
[Project1].[id] AS [id1],
[Project1].[name] AS [name1],
[Project1].[pucrhase] AS [pucrhase1],
[Project1].[sale] AS [sale1]
FROM Area
ORDER BY [Project1].[id] DESC, [Project1].[name] ASC, [Project1].[pucrhase] ASC,
[Project1].[sale] ASC,N',@p__linq__1 int,@p__linq__1=10
I have not requested for any Ordering , Order By Clause . EF adds ORDER BY clause by Itself to Query. Order By clause added contains all columns of table.This table has 3 millions records and Query is timing Out as it is Ordering by All columns .
I tested by removing Order By it took Less then a second to finish
So Question is
how to Stop Entity framework(support of Web Api Odata ) from sending Order By clause to Sql Query.
How to remove Order By clause from SQL Query Entity framework(Web Api Odata) runs on Server?
Any Help is appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…