-1

I want to search address by linq, I use in 2 ways:

Linq:

_db.Address.Where(address => address.FullName.Contains(text));

Dynamic Linq:

_db.Address.Where("FullName.Contains(@0)", text);

When I try:

-> text value is string (doesnot contain space), the result in 2 querys is the same,

-> text value is number or string with space inside, the query 1 return right result, and the second one return null

I don't have Sql Profiler, so I cannot check the general sql.

How to fix this issus and how to work with dynamic linq in right way?

Stiger
  • 1,189
  • 2
  • 14
  • 29

1 Answers1

2

I think you need to do this way:

_db.Address.Where("FullName like @0", text);

or you can do like this as well:

_db.Address.Where(a => SqlMethods.Like(a.FullName, "%"+text+"%"))

See more Details HERE

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
  • The first way return me this error: `Expression of type 'Boolean' expected`. I want to search dynamic (not only `FullName` property), so the second way maybe not a good approach. – Stiger May 29 '14 at 05:09