Answer the question
In order to leave comments, you need to log in
Loop when loading related entity, how to fix?
There are two such classes:
public class A
{
[Required]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Description { get; set; }
public List<B> B { get; set; }
public List<C> C { get; set; }
public A()
{
B = new List<B>();
C = new List<C>();
}
}
public class B
{
[Required]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Description { get; set; }
public List<D> D { get; set; }
public List<E> E { get; set; }
[Required]
public int AId { get; set; }
public A A { get; set; }
public B()
{
D = new List<D>();
E = new List<E>();
}
}
A a = await _context.A
.Include(d => d.B).Include(d => d.C)
.FirstAsync(d => d.Id == id);
{
"code": 0,
"error": null,
"data": {
"id": 2,
"name": "abc",
"description": "The",
"B": [
{
"id": 2,
"name": "ABC",
"description": "The",
"D": null,
"E": null,
"AId": 2,
"A": {
"id": 2,
"name": "abc",
"description": "The",
"B": [
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question