C
C#4mo ago
Trou

C# .Net Core WebAPI Cyclic Dependancy

Hello, trying to make simple web api, have two classes Character and Episode both classes has nav property to other, wit ManyToMany relationship. The problem is when i trying to Get data json data looks like this; [ { "name": "Pika", "status": "asdasd", "species": "adasd", "gender": "Male", "image": "adsas", "episodes": [ { "name": "EP1", "airDate": "22323", "episodeCode": "asdadEP", "characters": [ null ], "id": 1, "createdAt": "2024-03-03T18:40:23" } ], "id": 3, "createdAt": "2024-03-03T17:49:17" } ] Here is my entites public class Character : BaseEntity<long> { ...SomeProps public ICollection<Episode> Episodes { get; set; } } public class Episode : BaseEntity<long> { ...SomeProps public virtual ICollection<Character> Characters { get; set; } }
3 Replies
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Pobiega
Pobiega4mo ago
If you have bidirectional nav props, you need to project/select/map your data into DTOs that do not. JSON serialization doesn't support bidirectional props
Angius
Angius4mo ago
.Select() FTW