C# – NHibernate w/ Fluent – No persister for: [class]

cfluent-nhibernatenhibernate

I'm using NHibernate for the first time but wanted to be able to avoid config files if possible, by using NHibernate Fluent. I've got a project setup and I'm trying simply query for an adress object using the following

[TestMethod]
public void TestMethod1()
{
    var cfg = Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.Is("[ConnectionStringHere")))
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<RedSand.Models.Data.Mapping.AddressMapping>());

    var sessionFactory = cfg.BuildSessionFactory();

    var session = sessionFactory.OpenSession();

    session.Get<Address>(new Guid("A8B9BA39-425D-4AE6-A72E-00216ABC87C4"));
}

However it's blowing up on the Get<T>() method with an error complaining about there being no persister. My address classes are below.

public class Address
{
    public Guid AddressId { get; set; }
    public string AddressType { get; set; }
    public string StreetAddress { get; set; }
    public Guid CityId { get; set; }
    public string PostalCode { get; set; }
    public bool DefaultAddress { get; set; }
    public bool TermAddress { get; set; }
    public string SuiteNumber { get; set; }
    public float Latitude { get; set; }
    public float Longitude { get; set; }
    public int Accuracy { get; set; }
}

public class AddressMapping : ClassMap<Address>
{
    public AddressMapping()
    {
        Table("tblAddress");
        Not.LazyLoad();
        Id(a => a.AddressId).Column("AddressID").GeneratedBy.Guid();
        Map(a => a.StreetAddress).Column("Address").Length(100);
        Map(a => a.CityId).Column("CityID");
        Map(a => a.PostalCode).Length(50);
        Map(a => a.DefaultAddress);
        Map(a => a.TermAddress).Default("0");
        Map(a => a.SuiteNumber).Column("SuiteNo").Length(50);
        Map(a => a.Latitude);
        Map(a => a.Longitude);
        Map(a => a.Accuracy);
    }
}

I'm using an existing database so try to ignore the funky table structure/naming.

Am I missing something here? Can any of you see something that would explain why it's complaining about a No persister?

Best Answer

The assembly in AddFromAssemblyOf should be a mapped class, not a mapping file. Is Address in a different assembly than AddressMapping? Try changing it to AddFromAssemblyOf<YourNamespace.Address>.

Related Topic