no persister for: Fluent nHibernate Exception

2019-07-04 11:53发布

问题:

i m getting the exception "No persister for: MVCTemplate.Common.Entities.User" . I Google this issue and apply all the solution i found. but all are useless for me. Does anyone know what i m doing wrong ?

my User Class code is

public class User
{
    public virtual Guid UserID { get; private set; }
    public virtual string UserName { get; set; }
    public virtual string Password { get; set; }
    public virtual string FullName { get; set; }
    public virtual string Email { get; set; }
    public virtual TimeSpan LastLogin { get; set; }
    public virtual bool IsActive { get; set; }
    public virtual DateTime CreationDate { get; set; }
    public virtual IList<UserInRole> UserInRoles { get; set; }
}

User Mapping :

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Table("tblUsers");
        Id(user => user.UserID).GeneratedBy.GuidComb();
        Map(user => user.UserName).Not.Nullable();
        Map(user => user.Password).Not.Nullable();
        Map(user => user.FullName).Not.Nullable();
        Map(user => user.Email).Not.Nullable();
        Map(user => user.LastLogin).Not.Nullable();
        Map(user => user.IsActive).Nullable();
        Map(user => user.CreationDate).Not.Nullable();
        HasMany(user => user.UserInRoles);
    }
}

FNH Configuration :

return Fluently.Configure()
            .Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008
            .ConnectionString(c => c.FromConnectionStringWithKey("FNHConnection"))
            )
            .Mappings(m =>
                m.FluentMappings.AddFromAssemblyOf<User>())
            .BuildSessionFactory();

Thanks

回答1:

Double check that your mapping class is public.

Check that you have something like this in your fluent config....

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