I'm trying to make odata rest-based service calls through a URI.
I have an ADO.NET Entity data model that is mapped to one of the tables on the SQL back end. Which created the necessary edmx file under my "Models" folder
I then created a controller labeled spcontrol using the "Web API 2 Odata Controller with actions, using Entity Frameowrk" option. I then set the model class and Data context class and the visual studio scaffolding did the rest. The first few lines of the controller look like this...
public class spcontrolController : ODataController
{
private Entities db = new Entities();
// GET odata/spcontrol
[Queryable]
public IQueryable<Database_table_Name> Getspcontrol()
{
return db.Database_table_Name;
}
// GET odata/spcontrol(5)
[Queryable]
public SingleResult<Database_table_Name> GetDatabase_table_Name([FromODataUri] int key)
{
return SingleResult.Create(db.Database_table_Name.Where(Database_table_Name=> Database_table_Name.ID == key));
}
and then it goes on for the PUT, POST, PATCH, DELETE methods. In my WebApiConfig.cs file, I set the following lines
using System.Web.Http.OData.Builder;
using resttest.Models;
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Database_table_Name>("spcontrol");
config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());
Finally, I'm trying to query the table with odata. So my url looks something along the lines of
http://testsite:8012/odata/spcontrol?$top=5
However, this call does not return any data, but only returns the following text
{
"odata.metadata":"http://localhost:33421/odata/$metadata#spcontrol","value":[
]
}
How can I get the actual values within the SQL table? What am I doing wrong?