多表连接 HQL(带有 Fluent nHibernate 的 ASP.NET MVC 2)
我有一个用 ASP.NET MVC 和流畅的 NHibernate 编写的 Web 应用程序。 我有 4 个层次结构表。哪个
投票->后->类别->公司简介
我尝试构建一个查询,其中列出了过去 3 天内投票的所有公司帖子。
对公司进行投票:
IList<Vote> votes = session.CreateCriteria(typeof(Vote))
.CreateAlias("Post", "post")
.CreateAlias("Category", "category")
.Add(Restrictions.Eq("category.Company", pCompany))
.Add(Restrictions.Between("VoteDate", DateTime.Today.AddDays(-3), DateTime.Today))
.List<Vote>();
对上述投票进行帖子:
IList<Post> companyPosts= votes.Select(v=> v.Post).ToList();
根据类别对帖子进行分组:
List<IGrouping<int, Post>> groupbyTopic =
(List<IGrouping<int, Post>>)
(from p in companyPosts group p by p.Topic.Id);
CreateCriteria gives error.
NHibernate.QueryException: could not resolve property: Topic of: App.Models.Vote
对于有效查询的任何建议和良好推荐,该查询将列出过去 3 天内投票的所有公司帖子。
I have a web application written in asp.net mvc with fluent nhibernate.
I have 4 tables in hierarchy. Which
Vote -> Post -> Category -> Company
I try to build a query which will list all company posts which voted in last 3 days.
Take Votes of Company :
IList<Vote> votes = session.CreateCriteria(typeof(Vote))
.CreateAlias("Post", "post")
.CreateAlias("Category", "category")
.Add(Restrictions.Eq("category.Company", pCompany))
.Add(Restrictions.Between("VoteDate", DateTime.Today.AddDays(-3), DateTime.Today))
.List<Vote>();
Take Posts of above votes:
IList<Post> companyPosts= votes.Select(v=> v.Post).ToList();
Grouping Posts based on Category :
List<IGrouping<int, Post>> groupbyTopic =
(List<IGrouping<int, Post>>)
(from p in companyPosts group p by p.Topic.Id);
CreateCriteria gives error.
NHibernate.QueryException: could not resolve property: Topic of: App.Models.Vote
Any suggestion and good recommandation for an efficient query which will list all company posts which are voted in last 3 days.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还没有指定别名=>
.CreateAlias("post.Category", "category")
或者您可以这样查询:
you havent specified the alias =>
.CreateAlias("post.Category", "category")
alternativly you can query like this: