© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
27 replies
Avalari

[Entity Framework] Issues with .Include()

Hi all! I have some issues trying to get data from my SQL Db.

Having 3 models (Set, SetContent and Item):
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>();
    }
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>();
    }


I have 3 pages:
- one to display all Sets
- one to display Content of specific Set
- one to display the specific Item details

The issue that I have is with the third one.
For the Item view page I would like to have a segment showing in what <Set> you can find it.

So my question is how should I form the call in order to get something like Item with SetContent with Set (name and releaseDate):
{
  "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"
    }
  ]
}
{
  "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"
    }
  ]
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ Entity Framework Migration Issues
C#CC# / help
3y ago
Entity Framework Cascade Delete Issues
C#CC# / help
3y ago
❔ entity framework, update entity with relations
C#CC# / help
4y ago
Entity framework
C#CC# / help
14mo ago