If so I can just write a method once and put it in the repository, however I thought there would be an easier way of doing this. What if my entity had 30 string fields? I have to check each one... seems a bit much.
For a very complicated issue of searching, I suggest you to package that into the EF by referring the Stored Procdure, and then directly use that instead.
outhowz42
Member
80 Points
121 Posts
Search all string fields of an entity LIKE SQL?
Nov 12, 2012 12:03 PM|LINK
If I have an entity with 10 string properties, how can I search all ten properties with a LIKE condition?
For example, in SQL:
SELCT * FROM suppliers
WHERE supplier_name LIKE '%bob%'
How can you accomplish this in EF? Thanks in advance.
Nick Asiimwe
Participant
1459 Points
643 Posts
Re: Search all string fields of an entity LIKE SQL?
Nov 12, 2012 12:08 PM|LINK
you can use the contains or StartsWith keyword. Some thing like
Sincerely,
Nick
ASP.NET, SQL Server [Database Engine, SSIS & SSRS],Entity Framework, C# and VB.NET
outhowz42
Member
80 Points
121 Posts
Re: Search all string fields of an entity LIKE SQL?
Nov 12, 2012 12:52 PM|LINK
Ok, but do I have to look in all fields manually?
supplier_name.Contains(bob) OR
supplier_address.Contains(bob) OR
...
supplier_description.Contains(bob)
If so I can just write a method once and put it in the repository, however I thought there would be an easier way of doing this. What if my entity had 30 string fields? I have to check each one... seems a bit much.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Search all string fields of an entity LIKE SQL?
Nov 13, 2012 12:29 AM|LINK
For a very complicated issue of searching, I suggest you to package that into the EF by referring the Stored Procdure, and then directly use that instead.
For more you can refer to this:
http://msdn.microsoft.com/en-us/data/gg699321.aspx