EF Query получает операцию включения для предупреждения о недоступности навигации - PullRequest
1 голос
/ 05 апреля 2020

У меня есть простой запрос

            clients = _context.Clients
               .Include(e => e.TrainerClients)
               .Include(e => e.User)
               .Where(e => e.TrainerClients.All(f => f.Status == UserStatus.Linked));

, который возвращает:

enter image description here

, но я получаю предупреждение, если выполняется как -is:

The Include operation for navigation '[e].User' is unnecessary and was ignored because the navigation is not reachable in the final query results.

Однако, если я закомментирую «Включить» (e => e.User) из запроса, я не получу предупреждение, но также не получу данные пользователя. ,

enter image description here

Так почему я получаю это предупреждение, и как я могу уточнить свой запрос, чтобы не получать предупреждение?

ОБНОВЛЕНИЕ: Модель клиента:

public class Client : BaseModel
{
    public string UserId { get; set; }
    [ForeignKey(nameof(UserId))]
    public ApplicationUser User { get; set; }    
    public DateTime LastPaidDate { get; set; }
    public string CreditCardNumber { get; set; }

    public ICollection<TrainerClient> TrainerClients { get; set; }
}

ApplicationUser:

public class ApplicationUser : IdentityUser
{
    public bool Facebook { get; set; }
    public string ProfilePicture { get; set; }
    public string CountryCode { get; set; }
    public string State { get; set; }
    public string City { get; set; }    
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public virtual DateTime? LastLoginTime { get; set; }
    public virtual DateTime? RegistrationDate { get; set; }

    public string Address { get; set; }
    public string ZipCode { get; set; }
    public int StateId { get; set; }

    //Properties Client used just for relation
    public Client Client { get; set; }

    public ProfileSetting ProfileSetting { get; set; }
}

TrainerClient:

public class TrainerClient : BaseModel
{
    public int TrainerId { get; set; }
    [ForeignKey(nameof(TrainerId))]
    public Trainer Trainer { get; set; }

    public int ClientId { get; set; }
    [ForeignKey(nameof(ClientId))]
    public Client Client { get; set; }

    public Enum.UserStatus Status { get; set; }

    public Enum.RequestType RequestType { get; set; }

    public string RequestDate { get; set; }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...