开发者

no persister for: Fluent nHibernate Exception

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(u开发者_运维技巧ser => 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


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


The following will cause this error in simple terms:

private static void MainFN()
{
    using (var session = sessionFactory.OpenSession())
    {
        using (var transaction = session.BeginTransaction())
        {
            Data[] balance = new Data[12];
            for (int i = 0; i < 12; i++)
            {
                balance[i] = new Data();
                balance[i].Test1 = "Example Data " + (i + 1).ToString();
                balance[i].Test2 = i + 11;
                balance[i].Test3 = (i % 2 == 0);
                session.SaveOrUpdate(balance[i]); //Should be like this
            }
            //session.SaveOrUpdate(balance); //This will give the error
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜