I'm writing an odata web api following this guide My code is pretty much the same (some code has been removed for readability):
webapiconfig:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Delivery>("Versions");
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: null,
model: builder.GetEdmModel());
}
}
controller:
public class VersionsController : ApiController
{
DeliveryContext db = new DeliveryContext();
[EnableQuery]
public IQueryable<Delivery> Get()
{
return db.deliveries;
}
DeliveryContext
public partial class DeliveryContext : DbContext
{
public DeliveryContext()
: base("name=DeliveryContext")
{
}
public virtual DbSet<Delivery> deliveries { get; set; }
}
Running a GET from postman gives me:
[{"number":-1,"customer":"","version":"","othernumber":"","identitynumber":" "},{"number":123,"customer":"i00000","version":"8.5.2","othernumber":"564","identitynumber":"123"}]
My problem is that when I'm connecting to my odataservice in Power BI it complains about:
DataSource.Error: OData: An unexpected 'StartArray' node was found when reading from the JSON reader. A 'StartObject' node was expected. Details: DataSourceKind=OData DataSourcePath=http://localhost:51124/Versions
Finally, postman GET to the service:
{
"@odata.context":"http://localhost:51124/odataservice/$metadata","value":[
{
"name":"Versions","kind":"EntitySet","url":"Versions"
}
]
}
Any suggestions are greatly appreciated!
Ok I didn't solve my own problem but I don't have time to mess around with this anymore. I instead followed this guide and got it working in 10minutes. To be noted is that I had to use the nuget beta 1.0.0 package for it to work, otherwise I got error for the HttpConfiguration class not having a filter() method.