Ale*_*dyu 2 nhibernate nhibernate-3 queryover
我班级的简单例子:
public class Post
{
public IEnumerable<Tag> Tags { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
用户检查几个感兴趣的标签以过滤帖子列表.
我需要按选定的标签筛选所有帖子,例如:
Session.QueryOver<Post>()
.WhereRestrictionOn(x => x.Tags)
.IsIn(criterion.InterestedTags.ToList())
.List<Post>();
Run Code Online (Sandbox Code Playgroud)
例外: NHibernate.QueryException: Cannot use collections with InExpression
实际上,如果其中一个标签包含在InterestedTags中,我应该显示帖子.
UPD
适合我:
Session.QueryOver<Post>()
.JoinAlias(p => p.Tags, () => tag)
.WhereRestrictionOn(() => tag.Id)
.IsIn(criterion.InterestedTags.Select(x => x.Id).ToArray())
.List<Post>();
Run Code Online (Sandbox Code Playgroud)
您必须使用别名来限制one-to-many部分
请尝试以下代码段:
Tag tag = null;
Session.QueryOver<Post>()
.JoinAlias(p => p.Tags, () => tag)
.WhereRestrictionOn(() => tag.Id)
.IsIn(criterion.InterestedTags.ToList()) //*
.List<Post>();
Run Code Online (Sandbox Code Playgroud)
*假设InterestedTags是标识符的集合.
| 归档时间: |
|
| 查看次数: |
6462 次 |
| 最近记录: |