Я провел исследование по своей проблеме, но почему-то не понял.
У меня есть 4 класса со связанными сущностями в виде 1: n:
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; }
}
Мне нравитсяполучить все данные для проекта, который я пытаюсь получить таким образом, используя projectId из репозитория:
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;
}
Я могу перейти только на уровень "UrlTextContent", но я как-то не могувключить "UrlTextSnippet".
Моя цель - загрузить полный "Проект", чтобы иметь возможность выполнить некоторую обработку элементов списка связанных объектов.
В конце я хочу найти все«UrlTextContent», для которого «UrlTextSnippets» не доступен путем итерации по связанным объектам.
Я использую .NET Core 2.1.403 с Entity Framework Core .NET 2.1.4-rtm-31024
Любая помощь очень ценится.
С уважением
Редактировать:
Класс контекста:
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; }
}
Редактировать 2: Отладка скриншота
Список "UrlTextSnippet" пуст, хотя доступна одна запись.
