0

I want to use OWIN. But I need more columns in the user table. I also want to use NHibernate.

What is the way to do this? Extending the user table from OWIN. I don't know if that is possible. Second, I don't know whether I can get caching problems, or not.

Or, I make a second user table for my own user data with a "UserID" property as foreign key referencing to the user table for OWIN?

Matze
  • 5,100
  • 6
  • 46
  • 69
Xeddon
  • 429
  • 8
  • 18
  • This is precisely what Identity was designed for: extensibility. If you want extra properties on `ApplicationUser`, just add them. It's just like any other entity. Owin has nothing to do with Identity or authentication in general. Identity just happens to operate as an Owin middleware. – Chris Pratt Mar 06 '17 at 15:27
  • okey. And if i have table who not reference the user table (and contrariwise) which is complete independently entity from ApplicationUser i have to use NHibernate to get the data? – Xeddon Mar 07 '17 at 08:49
  • @Xeddon anything you have under identity and ApplicationUser are Handled by its own DbContext, and if you have other tables that are not related to ApplicationUser are handled by your own ORM, However if you want to have a UserId in those tables you can easily Map them in NHibernate as Foreign key to ApplicationUser Table as well. – Masoud Andalibi Mar 07 '17 at 11:43
  • But it is good to use my ORM to manipulate Properties from ApplicationUser? Maybe i can get caching problems? (I manipulate from ORM and than from Identity and than again from ORM) – Xeddon Mar 08 '17 at 11:50
  • @Xeddon Identity model has its own ORM which is installed separately from The Entity Framework, I recommend using its own ORM to manipulate its own Tables and Data. – Masoud Andalibi Mar 09 '17 at 09:41

1 Answers1

1

I'd say use the Asp.NET Identity anyways. if you want to have more properties for your ApplicationUser you can add them like below:

public class ApplicationUser : IdentityUser
{
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }

    // Your Extended Properties
    public string FirstName{ get; set; }
    public string LastName{ get; set; }
    //...
}

You can even create methods for User.Identity to get the values of the properties as easily as GetUserId() method. Take a Look at this.

Community
  • 1
  • 1
Masoud Andalibi
  • 3,168
  • 5
  • 18
  • 44