Identity isn't coming from the database so it won't have all the information. The good news is that with the ID, it's easy to find your user's full record. Use UserManager<TUser>.FindByIdAsync()
and feed it the result of User.Identity.GetUserId()
. There's a FindByNameAsync()
method too if you want.
edit: This post was originally tagged ASP.NET Identity, so I thought you were using ASP.NET Identity, which uses the UserManager class. You may not have GetUserId() in this case. Anyway, the principle is the same, even if you want to, as you've said in the comments here, access things from User.Identity. Write an extension method to IIdentity that uses your database and searches the users table for a user whose username matches the one you have. Might look something like this:
public static int GetCompanyId(this IIdentity identity)
{
using (var context = new ApplicationDbContext())
{
return context.Users.Single(u => u.UserName == identity.GetUserName()).CompanyId;
}
}
You can then call this by using User.Identity.GetCompanyId()
.