This project is read-only.

Setup

First you need install the package:

     PM> Install-Package NHibernate.Identity

After you installed you need to bind the mappings:

.Mappings(m => m.FluentMappings.AddFromAssemblyOf<IdentityUser>())

 

Usage

After the setup you need to create UserManager and RoleManager:

var users = new UserManager<IdentityUser>(new UserStore<IdentityUser>(NHibernateHelper.GetSession());

var roles = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(NHibernateHelper.GetSession());

 

and use UserManager and RoleManager as you used before, for more information: http://www.asp.net/identity

 

Custom Identity User

Create class that inherits from IdentityUser, name it as you want:

public class ApplicationUser : IdentityUser
{
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
}

 

And create mapping class that inherits from IdentityUserMap:

public class ApplicationUserMapping : IdentityUserMap<ApplicationUser>
{
    public ApplicationUserMapping()
    {
        Map(x => x.FirstName);
        Map(x => x.LastName);
    }
}

 

Now change your UserManager instance creating to look like:

var users = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(NHibernateHelper.GetSession());

 

Custom Identity Role

Create class that inherits from IdentityRole, name it as you want:

public class ApplicationRole : IdentityRole
{
    public virtual string Something { get; set; }
}

 

And create mapping class that inherits from IdentityRoleMap:

public class ApplicationRoleMapping : IdentityRoleMap<ApplicationRole>
{
    public ApplicationRoleMapping()
    {
        Map(x => x.Something);
    }
}

 

Now change your RoleManager instance creating to look like:

var roles = new RoleManager<ApplicationRole>(new RoleStore<ApplicationRole>(NHibernateHelper.GetSession());

 

 

 

var users = new UserManager<IdentityUser>(new UserStore<IdentityUser>(NHibernateHelper.GetSession());

Last edited Jan 15, 2014 at 12:38 PM by RafaelZilberman, version 2