我得到了异常“没有持久性:MVCTemplate.Common.Entities.User”。我谷歌这个问题,并应用我找到的所有解决方案。但对我来说都没用。 有谁知道我做错了什么?
我的用户类代码是
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; }
}
用户映射:
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配置:
return Fluently.Configure()
.Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.FromConnectionStringWithKey("FNHConnection"))
)
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<User>())
.BuildSessionFactory();
由于
答案 0 :(得分:8)
仔细检查您的地图类是否公开。
检查您的流畅配置中是否有类似的内容....
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>())