1

I'm developing an application with jaydata, OData and web api. Source code is given below:

$(document).ready(function () {

        $data.Entity.extend('$org.types.Student', {
            Name: { type: 'Edm.String', nullable: false, required: true, maxLength: 40 },
            Id: { key: true, type: 'Edm.Int32', nullable: false, computed: false, required: true },
            Gender: { type: 'Edm.String', nullable: false, required: true, maxLength: 40 },
            Age: { type: 'Edm.Int32', nullable: false, required: true, maxLength: 40 }
        });

        $data.EntityContext.extend("$org.types.OrgContext", {
            Students: { type: $data.EntitySet, elementType: $org.types.Student },
        });

        var context = new $org.types.OrgContext({ name: 'OData', oDataServiceHost: '/api/students' });

        context.onReady(function () {
            console.log('context initialized.');
        });

    });

In above JavaScript code, I defined an entity named Student. In context.onReady() method, I'm getting the following error:

Provider fallback failed! jaydata.min.js:100

Any idea, how I could get rid of this error??

tereško
  • 58,060
  • 25
  • 98
  • 150

2 Answers2

0

As per suggested solution, I tried to change the key from required to computed. But sadly its still giving the same error. Modified code is given below.

$(document).ready(function () {

        $data.Entity.extend('Student', {
            Id: { key: true, type: 'int', computed: true },
            Name: { type: 'string', required: true}
        });

        $data.EntityContext.extend("$org.types.OrgContext", {
            Students: { type: $data.EntitySet, elementType: Student },
        });

        var context = new $org.types.OrgContext({
            name: 'OData',
            oDataServiceHost: '/api/students'
        });

        context.onReady(function () {
            console.log('context initialized.');
        });            
    });

I thinks the issue is with Odata provider because I tried the same code with indexdb provider and its working properly.

  • Does this work with web api as is? I noticed that you are referencing Odata and the host path is /api/students which seems to indicate web api instead of Odata. Is the Odata configuration interchangeable? Can this config be used for Odata as well as WebAPI? – Nate Jun 11 '14 at 02:02
0

The issue is caused by the value oDataServiceHost parameter. You should configure it with the service host, not with a particular collection of the service. I don't know if the provider name is case-sensitive or not, but 'oData' is 100% sure.

For WebAPI + OData endpoints the configuration should look like this:

var context = new $org.types.OrgContext({
  name: 'oData',
  oDataServiceHost: '/odata'
});
Robesz
  • 1,646
  • 11
  • 13