Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Fluent Nhibernate No persister for: <ClassName>

I got this error while working on the following class.   

   internal partial class OrganizationMap : ClassMap<Organization>
    {
        #region constructors
        internal OrganizationMap()
        {
            Id(x => x.OrganizationId).GeneratedBy.Assigned();
            Map(x => x.DateCreated).Generated.Always();
            Map(x => x.DateUpdated).Generated.Always();
            Map(x => x.VersionNumber).Generated.Always();
            Map(x => x.UUID);
            Map(x => x.Name);
       }

 }

 Here is the code I used to test it.

 var sessionFactory = CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {

                using (var transaction = session.BeginTransaction())
                {
                    var newOrganization = new Organization
                    {
                        OrganizationId = 150,
                        Name = "Organization 150",
                    
                        UUID = Guid.NewGuid()
                    };

                    //LINE THAT BREAKS
                    session.Save(newOrganization);
                    session.Flush(); //force the SQL INSERT
                    session.Refresh(newOrganization); //re-read the state (after the trigger executes)
                 

                    transaction.Commit();

                 
                }

In case of Nhibernate, mostly this error occurs if the hmb.xml is not marked as 'Embedded Resource'.

Solution: This error occurs since the class is not public. Just change the class to public and this won't occur again. However, if you do not want to expose the assembly outside the Assembly you can still mark the constructor as 'internal'. 

The only downside to it is that the class shows up in intellisense. However, you would get a compile time error if you try to use it.  So, I guess that works.

Truly speaking this would fix any logical errors but I don't personally like the idea of the classes being forced to have the access modifiers of public. 

2 Comments

Comments have been disabled for this content.