c# - GET api controller generating errors when eager loading -


i'm trying setup api controller in .net core pass model json jquery datatable keep getting connection errors when try eager load related model.

/api/projectscontroller.cs

using system.collections.generic; using system.linq; using system.threading.tasks; using microsoft.aspnetcore.http; using microsoft.aspnetcore.mvc; using microsoft.entityframeworkcore; using projectlogic.models;  namespace projectlogic.controllers.api {     [produces("application/json")]     [route("api/projects")]     public class projectscontroller : controller     {         private readonly projectlogicdbcontext _context;          public projectscontroller(projectlogicdbcontext context)         {             _context = context;         }          // get: api/projects         [httpget]         public async task<ienumerable<project>> getprojects()         {             var projects = await _context.projects                 //.include(p => p.pmemployee)                 .tolistasync();              return projects;         }          // get: api/projects/5         [httpget("{id}")]         public async task<iactionresult> getproject([fromroute] int id)         {             if (!modelstate.isvalid)             {                 return badrequest(modelstate);             }              var project = await _context.projects                 //.include(p => p.pmemployee)                 .singleordefaultasync(m => m.projectid == id);              if (project == null)             {                 return notfound();             }              return ok(project);         }     }     ... } 

i tried setting same syntax in get: api/projects/id thinking erroring out on data running on entire project table employee model linked, isn't case. if uncomment .include(p => p.pmemployee) entry on either method, err_connection_reset if inspect page in chrome. running api url through rested extension gives me "an error occured while fetching resource: typeerror: failed fetch". comment line back, save, build, refresh request , works against _context.projects.

project.cs

using system; using system.collections.generic;  namespace projectlogic.models {     public class project     {         public project()          public int projectid { get; set; }         public string projectname { get; set; }         public int? pmemployeeid { get; set; }         public employee pmemployee { get; set; }         ...     } } 

employee.cs

using system.collections.generic;  namespace projectlogiccore.models {     public class employee     {         public employee()         { pmprojects = new hashset<project>(); }          public int employeeid { get; set; }         public int employeetitleid { get; set; }         public string name { get; set; }         public icollection<project> pmprojects { get; set; }         ...     } } 

the classes work fine eager loading non-api controller handling other views , viewmodels , i've got separate project identical syntax in api controller works fine eager loading. can't figure out tripping httpget api.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -