I use ASP.NET Identity 2.0 and create two different user entities inherited from ApplicationUser as posted on Implementing Inheritance with the Entity Framework 6 in an ASP.NET MVC 5 but I cannot reach these custom properties and its values (StudentNumber and Profession) while reaching custom properties defined in ApplicationUser (Name, Surname). And idea?
Here is the code I tried to use for retrieving value Name
, Surname
, StudentNumber
and Profession
:
Controller:
public AccountController(ApplicationUserManager userManager,
ApplicationSignInManager signInManager)
{
UserManager = userManager;
SignInManager = signInManager;
}
private ApplicationUserManager _userManager;
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext()
.GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
[AllowAnonymous]
public ActionResult ListAccount(JQueryDataTableParamModel param)
{
var allUsers = UserManager.Users;
//code omitted for brevity
/* as there is no property StudentNumber and Profession in Users,
I cannot reach these properties while reaching other custom properties */
var result = from c in allUsers
select new[] { Convert.ToString(c.Id), c.Name, c.Surname, c.Email, c.PhoneNumber };
}
Models:
public abstract class ApplicationUser : IdentityUser
{
//snip
//Common properties
public string Name { get; set; }
public string Surname { get; set; }
}
I defined different type classes and inherited from the base class:
public class StudentUser : ApplicationUser
{
public string StudentNumber { get; set; }
}
public class ProfessorUser : ApplicationUser
{
public string Profession { get; set; }
}