如何急切地从 IdentityUser 加载城市。包含方法不起作用

How to eagerly load City From IdentityUser .Include Method not working

我正在 Asp.net MVC 中的 Wedding Hall 网站项目上工作。我正在使用 Asp.net 网络 API 构建 API。对于身份验证和授权,我使用 Asp.net 身份。我在 class 中学到了一些关于导航属性的知识,我正在尝试加载城市 class 信息 我遇到的问题是我无法使用 .Include 方法加载城市。使用以下代码,我在城市字段中获得空值。

我尝试使用 .Include 方法来快速加载城市 class 但该方法未显示。

public class ApplicationUser : IdentityUser
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string address { get; set; }
        public string MobileNumber { get; set; }
        public string CNIC { get; set; }
        public City City { get; set; }
        public int CityId { get; set; }

    }
public class UsersController : ApiController
    {
        private ApplicationDbContext context;
        public UsersController()
        {
            context = new ApplicationDbContext();
        }
        public IEnumerable<ApplicationUser> GetUsers()
        {
            return context.Users.ToList();
        }
    }

导入System.Data.Entity命名空间:

using System.Data.Entity;

导航属性必须定义为虚拟:

 public virtual City City { get; set; }