У меня есть проект ASP. NET Core 3.1, где я использую Entity Framework Core 3.1 в качестве ORM.
У меня есть следующие две модели сущностей
public class PropertyToList
{
public int Id { get; set; }
public int ListId { get; set; }
public int UserId { get; set; }
public int PropertyId { get; set; }
// ... Other properties removed for the sake of simplicity
public virtual Property Property { get; set; }
}
public class Property
{
public int Id { get; set; }
// ... Other properties removed for the sake of simplicity
public int TypeId { get; set; }
public int StatusId { get; set; }
public int CityId { get; set; }
public virtual Type Type { get; set; }
public virtual Status Status { get; set; }
public virtual City City { get; set; }
}
Я пытаюсь запросить все свойства, к которым имеет отношение пользователь. Объект PropertyToList
сообщает мне, связан ли пользователь со свойством. Вот что я сделал
// I start the query at a relation object
IQueryable<Property> query = DataContext.PropertyToLists.Where(x => x.Selected == true)
.Where(x => x.UserId == userId && x.ListId == listId)
// After identifying the relations that I need,
// I only need to property object "which is a virtual property in" the relation object
.Select(x => x.Property)
// Here I am including relations from the Property virtual property which are virtual properties
// on the Property
.Include(x => x.City)
.Include(x => x.Type)
.Include(x => x.Status);
List<Property> properties = await query.ToListAsync();
Но этот код выдает эту ошибку
Включение было использовано для незапрашиваемых объектов
Что может быть причиной этой проблемы? Как я могу это исправить?