Search code examples
c#.netnhibernatenhibernate-mapping

nhibernate mapping An association from the table Image refers to an unmapped class


I have two classes MyArticle and Image.

public class MyArticle : IArticle{
    ....
    public virtual List<Image> Images {get; set;}
}
public class Image{
    ...
    public IArticle Article {get; set;}
}

using nhibernate mapping by code I mapped those

public class ImageMap : ClassMapping<Image>
    {
        public ImageMap()
        {            
            ManyToOne(x => x.Article, m =>
            {
                m.NotNullable(true);
            });
        }
}

public class MyArticleMap: ClassMapping<MyArticle>
        {
            public MyArticleMap()
            {            
                Bag(x => x.Images,
              c => { },
              r => { r.OneToMany(); }
            );

            }
    }

When tried to unit test mapping it failes with error {"An association from the table Image refers to an unmapped class: MyApp.Model.IArticle"}


Solution

  • Try this:

    public class ImageMap : ClassMapping<Image>
    {
        public ImageMap()
        {            
            ManyToOne(x => x.Article, m =>
            {
                m.NotNullable(true);
                m.Class(typeof(MyArticle));
            });
        }
    }