【问题标题】:nHibernate 3 QueryOver with compound from clausenHibernate 3 QueryOver 与复合 from 子句
【发布时间】:2011-04-28 20:58:00
【问题描述】:

有没有人知道使用 nHibernate 3 QueryOver 语法从子句复合的方法 - 可以使用 Linq 到对象。我知道使用 Linq To nHibernate 是可能的,但我仍在努力了解 queryover api。

这是从 msdn 中获取的 Linq to objects 的示例:

var scoreQuery = from student in students
                 from score in student.Scores
                 where score > 90
                 select new { Last = student.LastName, score };

取自MSDN

【问题讨论】:

    标签: nhibernate linq-to-nhibernate queryover nhibernate-3


    【解决方案1】:

    您可以使用 QueryOver API 加入,但我认为您需要使用 Linq to Objects 将结果扁平化为匿名类型。

    类似这样的:

    session.QueryOver<Student> ()
        .JoinQueryOver (s => s.Scores).Where (s => s > 90)
        .Select (s => s.LastName, s => s.Scores)
        .List ()
        .SelectMany (s => s.Scores, (student, score) => new { Last = student.LastName, Score = score });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多