2 回答

TA貢獻1828條經(jīng)驗 獲得超3個贊
編寫您的GetProjects方法如下:
[HttpGet]
public IEnumerable<Project> GetProjects()
{
return _context.Projects.Include(p => p.Tasks).ToList();
}
然后為避免在類的方法中Self referencing loop添加以下配置:ConfigureServicesStartup
public void ConfigureServices(IServiceCollection services)
{
...
services.AddMvc()
.AddJsonOptions(
options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
);
...
}

TA貢獻1859條經(jīng)驗 獲得超6個贊
您可以使用如下所示的包含。您將在項目集合中獲得任務(wù)集合
// GET: api/Projects
[HttpGet]
public IEnumerable<Project> GetProjects()
{
return _context.Projects.Include(x=>x.Task);
}
- 2 回答
- 0 關(guān)注
- 133 瀏覽
添加回答
舉報