3
votes

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
Have you written your mapping for the 'User' ?Phill
yeh i have just add the mapping code in questionSaad
How are you adding your mapping to the NH Configuration? Is the assembly with the mappings in the bin directory of the application you're trying to run it from? The exception in question is to do when the session has no information about the object you're trying to persist.Phill
IsActive is not nullable, but in the mapping it is nullable - doubt thats the cause of this exception though...UpTheCreek
i have added the configuration also..Saad

1 Answers

8
votes

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>())