I'm using a .Net core backend with Entity Framework to retrieve objects to my angular2 frontend.
As long as I return flat objects from the backend I have not problems. But when I use an Linq Include
I get an net::ERR_CONNECTION_RESET
error. The error seems to occur as soon as the call returns from backend, but it never enters the result handler.
How can I return a complex object with lists inside the objects?
DocumentsController.cs:
[Produces("application/json")]
[Route("api/[controller]")]
public class DocumentsController : Controller
{
private readonly DatabaseContext _context;
public DocumentsController(DatabaseContext context)
{
_context = context;
}
// GET: api/Documents
[HttpGet]
public IEnumerable<Document> GetDocuments()
{
var documents = _context.Documents
.Include(x => x.Pages);
return documents;
}
}
Document.cs:
public class Document : IEntity
{
public int Id { get; set; }
public string Title { get; set; }
public string AlternativeTitle { get; set; }
public ICollection<Page> Pages { get; set; }
}
Page.cs:
public class Page : IEntity
{
public Document Document { get; set; }
public int DocumentId { get; set; }
public int Id { get; set; }
public string OriginalText { get; set; }
public int Sorting { get; set; }
}
documents.components.ts:
import { Component, Inject } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'documents',
templateUrl: './documents.component.html'
})
export class DocumentsComponent {
public documents: Document[];
constructor(http: Http, @Inject('BASE_URL') baseUrl: string) {
http.get(baseUrl + 'api/Documents').subscribe(result => {
this.documents = result.json() as Document[];
}, error => console.error(error));
}
}
interface Document {
title: string;
alternativeTitle: string;
pageCount: number;
pages: Array<Page>;
}
interface Page {
originalText: string;
sorting: number;
}