문제

I've this QueryOver where I select Log records where the Logs Name starts with D or F (using wildcards).

conv.InnerTransaction.Session.QueryOver<Log>()
    .Where(l => l.DateTime > _datetime)
    .And(
        l => l.Name.IsLike("D%") || l.Name.IsLike("F%")
     )

Instead I would like the name searching to be dynamically using values from a list. How can this be done?

I've tried something like:

var query = conv.InnerTransaction.Session.QueryOver<Log>()
            .Where(l => l.DateTime > _datetime);
foreach (var name in _names)
{
    query = query.And(l => l.Name.IsLike(name));
}

But that would result in multiple AND statements for each name in the list, whereas It just need to be a OR.

도움이 되었습니까?

해결책

Have you tried Disjunction? I had a similar requirement once, but I had to use Conjunction instead. Disjunction will or multiple conditions together.

var disjunction = new Disjunction();
var query = Session.QueryOver<Log>().Where(l => l.DateTime > _datetime);
foreach (var name in _names)
{
    disjunction.Add(Restrictions.On<Log>(log => log.Name).IsLike(name));
}
var queryResult = query.Where(disjunction).List<Log>();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top