Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Dynamic Like clause in LINQ How?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
john - 02 Feb 2008 12:13 GMT
I'm trying to build a LINQ expression that will use a dynamic construction
of a LIKE statement in the WHERE clause, it would look something like this
in SQL:

WHERE TaskGroup Like "*00*" OR TaskGroup Like "*20*"

It would be many variations on the above.

I know how use the LIKE clause in LINQ but not in this context, here is an
attempt that did not work, I also tried building it into a variable that
looked like the LINQ LIKE clause if I were to type it out (WHERE filterExp)
but it did not work either.

Thanks for any input

filterExp = ""

       i = InStr(1, strFilter, ":")

       Do Until i = 0

           filterExp = filterExp & """Like *" & Mid(strFilter, i - 2, 2) &
"*"""

           i = InStr(i + 1, strFilter, ":")

           If i <> 0 Then

               filterExp = filterExp + ", "

           End If

       Loop

       Dim grp As String() = {filterExp}

       Dim dbTask As New DataTaskDataContext

       Dim taskTbl = From tas In dbTask.tblTasks _

                     Where grp.Contains(tas.TaskGroup) _

                     Select tas
Steven Cheng[MSFT] - 04 Feb 2008 06:24 GMT
Hi John,

As for LIKE syntax query, I've found some similar threads discussing on
this, and some of them're using a string comparing approach to do the LIKE
query in LINQ:

http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/10/16/linq-to-sql-li
ke-operator.aspx

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1570290&SiteID=1

You may have a look to see whether it helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
   

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "john" <none@none.com>
>Subject: Dynamic Like clause in LINQ How?
[quoted text clipped - 43 lines]
>
>                      Select tas

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.