Search code examples
c#asp.net-corebreezeef-core-2.0

BreezeJs Ef Core migration problems


Recently We upgraded our back end web api from .Net 4.61 to .Net Core 2.0, We are using Breezejs, and we are Happy with it, after upgrading we faced two problem that could not find answer Online:

for upgrading all with did was:

we used this git as guidline: https://github.com/mikemichaelis/dnc/

but to summerize:

  1. used .Net standard library project and Scaffold-DbContext (with all needed dependencies)

  2. create a .Net Core 2.0 WebApi project with Breeze and Ef Core Dependencies

  3. migrate our Old controller to new project and removed Bugs

So here is first the problem: For List methods that just returns entities, it Works fine

but for Methods which returns a single Object , it gives:

    [HttpGet]
    public Choice ChoiceByID(int ID)
    {
        var result = this.PersistenceManager.Context.Choice
            .SingleOrDefault(n => n.ID == ID);
        return result;
    }

breeze error Error: Unable to convert this endpoint to an IQueryable

if we change code to return IQueryable:

    [HttpGet]
    public IQueryable<Choice> ChoiceByID(int ID)
    {
        var result = this.PersistenceManager.Context.Choice
            .Where(n => n.ID == ID);
        return result;
    }

it will Give:

breeze error Error: This EntityQuery ctor requires a valid json string. The following is not json

So far no luck to resolve the issues


Solution

  • After some digging and cloning breeze git, i found out what the problem is it seems breeze for efcore change how you should call your end points:

    previously first parameter wasnt there (or i didnt use it)

    request detail in fiddler

    so for resolve issue:

    1. change your controller as @Nkosi provided

    2. in your client, add following lines ( in your constructor):

      import * as breeze from 'breeze-client'; //import at top

      breeze.config.initializeAdapterInstance('uriBuilder', 'json') // add to your constructor