I've this setup with code first model:
public class TestContext :IdentityDbContext<TestUser>
{
public TestContext()
: base("TestConnection")
{
this.Configuration.LazyLoadingEnabled = false;
}
public DbSet<Customer> Customers{get;set;}
}
public class TestUser : IdentityUser
{
public virtual Customer Customer { get; set; }
}
public class Customer
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName {get; set;}
}
I've extended the IdentityUser to contain an instance of "Customer" Class.
Now consider this code:
var user = UserManager.FindById("some id");
if (user != null)
{
string str=user.Customer.FirstName; //since lazy loading is off, user.Customer is null and hence gives null reference exception.
}
since lazy loading is off, user.Customer is null and hence gives null reference exception. I'll be glad if anyone can help me in accessing the Navigation Properties of IdentityUser when LazyLoading is off.
Thanks.