简体   繁体   中英

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.

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?

Angular component:

在此处输入图片说明

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

I've managed to fix the problem.

Due to the circular reference inside of Entity Framework the JSON failed to parse.

I manged to fix it by adding this option inside the startup.cs:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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