help
Root Question Message
public class Set
{
public int Id { get; set; }
public string Name { get; set; }
public string Code { get; set; }
public DateTime? ReleaseDate { get; set; }
public string Type { get; set; }
public string? Series { get; set; }
public string? Description { get; set; }
public ICollection<SetContent> Content { get; set; }
}
--------------------------
public class SetContent
{
public int Id { get; set; }
public int SetId { get; set; }
public string? SetCode { get; set; }
public string? SetRarity { get; set; }
public string? SetRarityCode { get; set; }
public int ItemId { get; set; }
public virtual Item Item { get; set; }
}
--------------------------
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string Desc { get; set; }
public string ImageBig { get; set; }
public string ImageSmall { get; set; }
public List<SetContent> Sets { get; set; } = new List<SetContent>();
}
{
"id": 0,
"name": "string",
"type": "string",
"desc": "string",
"imageBig": "string",
"imageSmall": "string",
"sets": [
{
"id": 0,
"setId": 0,
"setCode": "string",
"setRarity": "string",
"setRarityCode": "string",
"Name": "string",
"ReleaseDate": "DateTime"
}
]
}
virtual
Items
and using .Include(i => i.Sets)
would just work.Select()
insteadSign In and Join Server To See
builder.Services.AddControllersWithViews()
.AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles);
Sign In and Join Server To See
Sign In and Join Server To See
Context.Items.Include(i => i.Sets).ThenInclude(s => s.Set)
var item = await _context.Items
.Where(s => s.Id == id)
.FirstOrDefaultAsync<Item>();
_context.Entry(item).Collection(s => s.Sets)
.Query()
.Include(b => b.Set)
.Load();
.Select()
Sign In and Join Server To See
.Include()
is eager, yes, but virtual
allows for lazy loading to be usedvirtual
there