简体   繁体   中英

Fluent Nhibernate QueryOver using “Or” and “And clause”

Suppose I have following domain models:

 public class Fund : EntityBase
    {
        public virtual string Name { get; set; }
        public virtual IList<FundDetail> FundDetails { get; set; }
        public Fund()
        {
            FundDetails=new List<FundDetail>();

        }
    }
  public class FundDetail : EntityBase
    {
        public virtual string Symbol { get; set; }
        public virtual Fund Fund { get; set; }
    }

Now i would like to get all funds where fund name or fund details ymbol contains some string value:

 var funds = _fundRepository.QueryOver()
                    .Left.JoinAlias(c => c.FundDetails, () => fundDetail)
                    .Future().ToList();

How to use "or" clause in QueryOver? so I need to query all funds where :

string filterVal="someval";
c=>c.Name.Lower().Contains(filterVal) or fundDetail.Symbol.Lower().Contains9filterVal

Thanks.

You could add a call to the Where method:

string filterVal = "someval";
var funds = _fundRepository.QueryOver<Fund>().
                .Where(c => c.Name.Lower().Contains(filterVal) ||
                           c.fundDetail.Symbol.Lower().Contains(filterVal))
                .Left.JoinAlias(c => c.FundDetails, () => fundDetail)
                .Future().ToList();

Check out this article to get an idea of all other options regarding QueryOver.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM