0

I want to get all PartitionStates by name where it exactly meets the partitionName or starts with it when containing a ..

This is the query I have

return session.QueryOver<PartitionState>()
        .Where(p => p.Name == partitionName)
        .WhereRestrictionOn(p => p.Name).IsLike(partitionName + ".", MatchMode.Start)
        .OrderBy(p => p.StartDate).Desc
        .Take(1)
        .SingleOrDefault<PartitionState>();

The above query produces an AND expression, but i want it to be an OR.

In SQL it should look like this:

SELECT TOP 1 * 
FROM PartitionState 
WHERE (Name = @partitionName OR Name like @partitionName+'.%') 
ORDER BY StartDate DESC
4

1 回答 1

0

似乎没有内置方法,但可以将限制传递给 where 方法。

return session.QueryOver<PartitionState>()
        .Where(Restrictions.Or(
              Restrictions.Where<PartitionState>(p => p.Name == partitionName),
              Restrictions.On<PartitionState>(p => p.Name).IsLike(partitionName + ".", MatchMode.Start)))
        .OrderBy(p => p.StartDate)
        .Desc.Take(1)
        .SingleOrDefault<PartitionState>();
于 2013-07-02T11:52:30.090 回答