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:
used .Net standard library project and Scaffold-DbContext (with all needed dependencies)
create a .Net Core 2.0 WebApi project with Breeze and Ef Core Dependencies
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
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)
so for resolve issue:
change your controller as @Nkosi provided
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