How to use OData from stored procedure?
I have defined a controller like this
public class ReportOdataController : ODataController
{
private DB_PLBEntities db = new DB_PLBEntities();
[EnableQuery]
public IQueryable<Stp_Select_Report_Result> GetReportOdata()
{
return db.Stp_Select_Report(null).AsQueryable();
}
}
But when I call it through uri /odata/ReportOdata?$inlinecount=allpages
it throws the following error :
The result of a query cannot be enumerated more than once.
I am new to programming so I don't understand why the error occurred or how to fix it ?
Just change(assuming db
(DB_PLBEntities
) is a List<T>
) :
return db.Stp_Select_Report(null).AsQueryable();
To :
return db.Stp_Select_Report(null).AsQueryable().ToList();
Hope this helps :)