简体   繁体   English

将具有一对多关系的.Net核心实体映射到Angular 2接口

[英]Mapping .Net Core Entities with One to Many relationship to Angular 2 interfaces

I'm creating a simple Blog using .Net Core C# and Angular 2. 我正在使用.Net Core C#和Angular 2创建一个简单的Blog。

Retrieving all the Posts worked fine, but I have now added an Array of Comments to each post and this has caused the following error: 检索所有帖子都工作正常,但是我现在为每个帖子添加了一个评论数组,这导致了以下错误:

在此处输入图片说明

Does TypeScript need more information about the comments? TypeScript是否需要有关注释的更多信息?

Angular component: 角组件:

在此处输入图片说明

API Method: API方法: 在此处输入图片说明

I've managed to fix the problem. 我设法解决了这个问题。

Due to the circular reference inside of Entity Framework the JSON failed to parse. 由于Entity Framework内部的循环引用,JSON无法解析。

I manged to fix it by adding this option inside the startup.cs: 我试图通过在startup.cs中添加此选项来修复它:

 services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM