Question

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"}

Was it helpful?

Solution

Try this:

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

OTHER TIPS

This mapping is wrong

public class MyArticleMap: ClassMapping<MyArticleMap>{...}

It should be

public class MyArticleMap: ClassMapping<MyArticle>{...}

And also the list of Images should be of Interface type like this.

public virtual IList<Image> Images {get; set;}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top