4

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

Saad
  • 1,312
  • 5
  • 17
  • 40
  • Have you written your mapping for the 'User' ? – Phill Jul 07 '11 at 06:42
  • yeh i have just add the mapping code in question – Saad Jul 07 '11 at 06:46
  • 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 Jul 07 '11 at 06:49
  • IsActive is not nullable, but in the mapping it is nullable - doubt thats the cause of this exception though... – UpTheCreek Jul 07 '11 at 06:51
  • i have added the configuration also.. – Saad Jul 07 '11 at 07:14

2 Answers2

8

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>())
UpTheCreek
  • 31,444
  • 34
  • 152
  • 221
  • An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. Getting this exception after applying ddFromAssemblyOf – Saad Jul 07 '11 at 07:08
  • So that's a step forward. Did you correct the boolean nullable problem? – UpTheCreek Jul 07 '11 at 07:47
  • yeah.. but gt the new exception "{"(XmlDocument)(3,6): XML validation error: The element 'composite-id' in namespace 'urn:nhibernate-mapping-2.2' has incomplete content. List of possible elements expected: 'meta, key-property, key-many-to-one' in namespace 'urn:nhibernate-mapping-2.2'."}" – Saad Jul 07 '11 at 07:51
  • 2
    @Saad, looks like you have a problem with a different mapping file. Figure out where you are using composite-ids and create a new question please. – Vadim Jul 07 '11 at 16:24
0

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
RotatingWheel
  • 1,023
  • 14
  • 27