开发者

Using "from in" in a LinqSpecs specification?

We're using LinqSpecs to create specifications for our NHibernate Linq queries and I have the following query:

from p in projects
  from pp in p.Personprojects
  where pp.Id.PersonId == userId
  select p

And I'd like to encapsulate the

 from pp in p.Personprojects   
 where pp.Id.PersonId == userId

part in a specification.

Is there any way to do that?

My current solution is

public override Expression<Func<Project, bool>> IsSatisfie开发者_StackOverflow社区dBy()
{
  return p => p.Personprojects.Count(pp => pp.Id.PersonId == _userId)>0;
}

which doesn't strike me as optimal...


Instead of comparing Count to 0, it's better to use Any:

public override Expression<Func<Project, bool>> IsSatisfiedBy()
{
    return p => p.Personprojects.Any(pp => pp.Id.PersonId == _userId);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜