Sheryf
Sheryf

Reputation: 71

Linq Contains operator doesnt work

Met a problem on linq use. When i use .Where(m=> m.Name == "name") it works but when i use .Where(m=> m.Name.Contains("name")) its not.

my query is

return summary.JoinAlias(s => s.District, () => district, NHibernate.SqlCommand.JoinType.LeftOuterJoin).Where(() => district.Name. == "ALEK"); <- works

return summary.JoinAlias(s => s.District, () => district, NHibernate.SqlCommand.JoinType.LeftOuterJoin).Where(() => district.Name.Contains("ALEK")); <- not works

Upvotes: 1

Views: 101

Answers (1)

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

Reputation: 123861

The JoinAlias is a part of QueryOver syntax. For Contains() we should use this:

return summary
    .JoinAlias(s => s.District, () => district
                  , NHibernate.SqlCommand.JoinType.LeftOuterJoin)
    .WhereRestrictionOn(() => district.Name) // here we say what to restrict
        .IsLike("ALEK", MatchMode.Anywhere)  // and we say to use LIKE
    ;                                        // matching as: %ALEK%

Check:

Upvotes: 1

Related Questions