Entity Framework: Get multiple linked Objects

.net-core c# entity-framework-core

Question

I conducted some study on my issue, but I still don't understand it.

I have 4 classes that are 1:n connected together.

public class ContentProtectionProject
{
    [Required]
    public int Id { get; set; }

    ...

    [Required]
    public List<UrlToProtect> UrlsToProtect { get; set; }

    [Required]
    public int AccountId { get; set; }

    [ForeignKey("AccountId")]
    public Account Account { get; set; }
}

public class UrlToProtect
{
    [Required]
    public int Id { get; set; }

    ...

    [Required]
    public List<UrlTextContent> UrlsTextContent { get; set; }

    [Required]
    public int ContentProtectionProjectId { get; set; }

    [ForeignKey("ContentProtectionProjectId")]
    public ContentProtectionProject ContentProtectionProject { get; set; }
}

public class UrlTextContent
{
    [Required]
    public int Id { get; set; }

    ...

    [Required]
    public List<UrlTextSnippet> UrlTextSnippets { get; set; }

    [Required]
    public int UrlToProtectId { get; set; }

    [ForeignKey("UrlToProtectId")]
    public UrlToProtect UrlToProtect { get; set; }
}

public class UrlTextSnippet
{
    [Required]
    public int Id { get; set; }

    ...

    [Required]
    public int UrlTextContentId { get; set; }

    [ForeignKey("UrlTextContentId")]
    public UrlTextContent UrlTextContent { get; set; }
}

I like to get all project data, which I attempt to do by projectId from a repository:

public async Task<ContentProtectionProject> GetContentProtectionProject(int contentprotectionProjectId)
{
    var contentProtectionProject = await _context.ContentProtectionProjects
        .Include(x => x.UrlsToProtect)
        .ThenInclude(u => u.UrlsTextContent)

        .FirstOrDefaultAsync(x => x.Id == contentprotectionProjectId);

    return contentProtectionProject;
}

I can only add "UrlTextContent," but for some reason I cannot include "UrlTextSnippet."

To be able to do some processing on the connected entities list items, I want to load a full "Project".

By repeatedly iterating through the connected entities, I wish to locate all "UrlTextContent" for which no "UrlTextSnippets" are accessible.

I use Entity Framework Core.NET 2.1.4-rtm-31024 and.NET Core 2.1.403.

Any assistance would be much appreciated.

Best wishes

Edit:

Context type:

public class DataContext : DbContext
{
    public DataContext(DbContextOptions<DataContext> options) : base (options) {}
    ...
    public DbSet<ContentProtectionProject> ContentProtectionProjects { get; set; }
    public DbSet<UrlToProtect> UrlToProtects { get; set; }
    public DbSet<UrlTextContent> UrlTextContents { get; set; }
    public DbSet<UrlTextSnippet> UrlTextSnippets { get; set; }
}

Edit 2: A snapshot of a bug

The "UrlTextSnippet" list is empty, despite the fact that there is one item.

enter image description here

1
1
10/28/2018 1:04:07 PM

Popular Answer

ZZZ_tmp
2
11/3/2018 5:04:26 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow