Reputation: 8674
I have this class
public class ApplicationUser : IdentityUser
{
public string Email { get; set; }
public string ConfirmationToken { get; set; }
public bool IsConfirmed { get; set; }
...
}
and in DbContext class this is what I've done
public partial class PickerDbContext : IdentityDbContext
{
public PickerDbContext():base("DefaultConnection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().ToTable("Users");
modelBuilder.Entity<IdentityUser>().ToTable("Users");
modelBuilder.Entity<IdentityRole>().ToTable("Roles");
}
//public DbSet<License> Licenses { get; set; }
....
}
now when I try to query the Users
table in my repository with something like
var user = _db.Users.SingleOrDefault(u=>u.anyfield);
I think it has return type as IdentityUser
and not ApplicationUser
because when I do u=>u.
intellisense option doesn't show the fields from ApplicationUser
What should I do to make the querying in Users
table return ApplicationUser
type and why is it giving me return type as IdentityUser
Upvotes: 3
Views: 3496
Reputation: 33071
Because IdentityDbContext is not a class you defined, and ApplicationUser is a class that you did define. You create ApplicationUser that inherits from IdentityUser. You create a context that inherits from IdentityDbContext. IdentityDbContext exposes DbSet.
If you want the data to come back as ApplicationUser you can do the following:
context.Users.OfType<ApplicationUser>();
You may also be able to do this in your custom DbContext (unverified):
public new DbSet<ApplicationUser> Users { get; set; }
I haven't tested that though.
Upvotes: 6