I have a table called UserPermissions with a FK to the users table by userId and then a string column for the string value of an enum.
The error I am seeing is NHibernate.MappingException: An association from the table UserPermissions refers to an unmapped class: GotRoleplay.Core.Domain.Model.Permission
My Permission Enum:
public enum Permission
{
[StringValue("Add User")]
AddUser,
[StringValue("Edit User")]
EditUser,
[StringValue("Delete User")]
DeleteUser,
[StringValue("Add Content")]
AddContent,
[StringValue("Edit Content")]
EditContent,
[StringValue("Delete Content")]
DeleteContent,
}
The property in my User class:
public virtual IList<Permission> Permissions { get; set; }
My database table:
CREATE TABLE dbo.UserPermissions
(
UserPermissionId int IDENTITY(1,1) NOT NULL,
UserId int NOT NULL,
PermissionName varchar (50) NOT NULL,
CONSTRAINT PK_UserPermissions PRIMARY KEY CLUSTERED (UserPermissionId),
CONSTRAINT FK_UserPermissions_Users FOREIGN KEY (UserId) REFERENCES Users(UserId),
CONSTRAINT U_User_Permission UNIQUE(UserId, PermissionName)
)
My attempt at mapping the permissions property of my user object:
HasManyToMany(x => x.Permissions)
.WithParentKeyColumn("UserId")
.WithChildKeyColumn("PermissionName")
.WithTableName("UserPermissions")
.LazyLoad();
What am I doing wrong that it can't map the permission to a list of enum values?