I am using ASP.NET MVC, Identity2. I have added a custom property (address) to ApplicationUser
:
public class ApplicationUser : IdentityUser<long, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
public long? ProfileAddressId { get; set; }
// note that address is not virtual
[ForeignKey("ProfileAddressId")]
public Address ProfileAddress { get; set; }
}
Address
, is a separate table, that I have in my DB.
Now in my controller, I want to get the user (and load it's address):
public ActionResult MyAction()
{
var applicationUserManager = System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>();
var userId = User.Identity.GetUserId<long>();
// this does not load address
var user = applicationUserManager.FindById(User.Identity.GetUserId<long>());
}
Address
is not virtual
, and I have disabled lazy loading in ApplicationDbContext
:
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, CustomRole, long, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
public ApplicationDbContext()
: base("myDB")
{
// Lazy loading is enabled by default - disable lazy loading
Configuration.LazyLoadingEnabled = false;
}
// more code...
}
I don'w know why Address
is not being loaded?
How can I extend ApplicationUserManager
to include address? Or would it be possible to configure EF to always eager load related entities?