NHibernte CreateAlias for 2 multiply class

NHibernte CreateAlias for 2 multiply class

我有 3 类:书籍、类型、作者

public class Book {
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }

    public virtual string Description { get; set; }

    public virtual int MfRaiting { get; set; }

    public virtual int PageNumber { get; set; }

    public virtual IList<Genre> Genres { get; set; }


    public virtual Series Series { get; set; }

    public virtual Mind Mind { get; set; }

    public virtual IList<Author> Authors { get; set; }
    public Book() {
        Genres = new List<Genre>();
        Authors = new List<Author>();
    }

}
public class Genre {
    public virtual int Id { get; set; }

    public virtual string Name { get; set; }
    public virtual IList<Book> Books { get; set; }

    public Genre() {
        Books=new List<Book>();
    }
}
public class Author {
    public virtual int Id { get; set; }

    public virtual string Name { get; set; }

    public virtual string SurName { get; set; }

    public virtual string Biography { get; set; }

    public virtual IList<Book> Books { get; set; }

    public Author() {
        Books=new List<Book>();
    }
}

和他的 classMaps

public class BookMap : ClassMap<Book> {
    public BookMap() {
        Id(x => x.Id);
        Map(x => x.Name);
        HasManyToMany(x => x.Genres)
            .Cascade.All()
            .Table("Book_Genre");
        HasManyToMany(x => x.Authors)
            .Cascade.All()
            .Table("Book_Author");
        References(x => x.Series);
        HasOne(x => x.Mind).Constrained();
    }
}
public class GenreMap : ClassMap<Genre> {
    public GenreMap() {
        Id(x => x.Id);
        Map(x => x.Name);
        HasManyToMany(x => x.Books)
            .Cascade.All()
            .Inverse()
            .Table("Book_Genre");
    }
}
public class AuthorMap : ClassMap<Author> {
    public AuthorMap() {
        Id(x => x.Id);
        Map(x => x.Name);
        Map(x => x.SurName);
        Map(x => x.Biography);
        HasManyToMany(x => x.Books)
            .Cascade.All()
            .Inverse()
            .Table("Book_Author");
    }
}

当我尝试写代码时 变量标准 = session.CreateCriteria(); criteria.CreateAlias("Genres", "genre", JoinType.LeftOuterJoin); 它运作良好,但当我这样做时

public ActionResult Index()
{
   var criteria = session.CreateCriteria<Book>();
   criteria.CreateAlias("Genres", "genre", JoinType.LeftOuterJoin);
   criteria.CreateAlias("Authors", "author", JoinType.LeftOuterJoin);
   criteria.SetResultTransformer(new DistinctRootEntityResultTransformer());
}

我看到异常无法同时提取多个包。我怎样才能得到该标准的结果?

感谢

我解决了这个问题!我在 ISet 上替换了 IList,在新的 HashSet<"Class">

上替换了新的 List<"Class">

我在这里读到了这个问题。 http://developer-should-know.tumblr.com/post/118012584847/jpa-fetching-strategies 只有一个使用JOIN策略获取的集合可以是List类型,其他集合必须是Set类型。否则会抛出异常:

HibernateException: 不能同时获取多个包