Aline Bossi
Aline Bossi

Reputation: 63

Is it possible use the like command in queryover nHibernate? How can I do this?

I want to search through parts of the record, not only in accurate records. In this exemple I search for the accurate records:

var v = NhSession.QueryOver<Dados.Models.PersonModel>()
            .Where(w=>w.Name == "Mary"))
            .List();

I can do this by queryover or only with criteria?

Upvotes: 1

Views: 47

Answers (1)

Radim K&#246;hler
Radim K&#246;hler

Reputation: 123861

The answer is in the: WhereRestrictionOn. It could look like this

var v = NhSession
    .QueryOver<Dados.Models.PersonModel>()
    //.Where(w => w.Name == "Mary"))
    .WhereRestrictionOn(w => w.Name)
      .IsLike("Mary", MatchMode.Start);
    .List();

The MatchMode enum will decide where to put the '%' generated SQL Statement

Upvotes: 1

Related Questions