首页 新闻 会员 周边

NHibernate中多对多的hql查询语句怎么写?

0
悬赏园豆:10 [已关闭问题] 关闭于 2014-11-25 14:37

Student表与Score表是多对多的关系,这两张表有个中间表,因中间表没有主键,故不能直接查中间表。我现在需要查询Student中ScoreId>10的数据。

var hql="from Student s left join fetch s.Scores score where score.ScoreId>10";

  这样写查询时报错。

Student实体

[Class(Table = "Student", OptimisticLock = OptimisticLockMode.Version, DynamicUpdate = true)]
[Cache(Usage = CacheUsage.ReadWrite)]
[Serializable]
public class Student
{
    [Id(0, TypeType = typeof(int), Name = "Id", UnsavedValue = "0")]
    [Column(1, Name = "sid", NotNull = true, SqlType = "number")]
    [Generator(2, Class = "sequence")]
    [Param(3, Name = "sequence", Content = "s_student")]
    public virtual int Id{get;set;}
    
    [Property(Column = "sname")]
    public virtual string SName{get;set;}
    
    [Bag(0, Name = "Scores", Table = "Score")]
    [Key(1, Column = "sid", NotNull = true)]
    [ManyToMany(2,Column = "scoreId",ClassType = typeof(Score),Fetch=FetchMode.Join,Lazy=RestrictedLaziness.Proxy)]
    public virtual IList<Score> Scores { get; set; }
}

Score实体

[Class(Table = "Score", OptimisticLock = OptimisticLockMode.Version, DynamicUpdate = true)]
[Cache(Usage = CacheUsage.ReadWrite)]
[Serializable]
public class Score
{
    [Id(0, TypeType = typeof(int), Name = "Id", UnsavedValue = "0")]
    [Column(1, Name = "scoreId", NotNull = true, SqlType = "number")]
    [Generator(2, Class = "sequence")]
    [Param(3, Name = "sequence", Content = "s_score")]
    public virtual int Id{get;set;}
    
    [Property(Column = "scorename")]
    public virtual string ScoreName{get;set;}
}
xiaoafei1991的主页 xiaoafei1991 | 菜鸟二级 | 园豆:466
提问于:2014-11-25 14:08
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册