nhibernate映射表Image中的关联是指未映射的类

时间:2014-04-23 19:33:45

标签: c# .net nhibernate nhibernate-mapping

我有两个类MyArticle和Image。

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

使用代码的nhibernate映射我映射了那些

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(); }
            );

            }
    }

当尝试单元测试映射时,它会出错并出错 {“表格中的关联图像是指未映射的类:MyApp.Model.IArticle”}

2 个答案:

答案 0 :(得分:2)

试试这个:

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

答案 1 :(得分:0)

此映射错误

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

应该是

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

此外,图像列表应该是这样的接口类型。

public virtual IList<Image> Images {get; set;}