Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dynamic Like clause in LINQ How?

Reply
Thread Tools

Dynamic Like clause in LINQ How?

 
 
john
Guest
Posts: n/a
 
      02-02-2008
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



 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      02-04-2008
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/b...linq-to-sql-li
ke-operator.aspx

http://forums.microsoft.com/MSDN/Sho...70290&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" <>
>Subject: Dynamic Like clause in LINQ How?
>Date: Sat, 2 Feb 2008 07:13:01 -0500
>
>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
>
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linq where clause EdisonCPP ASP .Net 8 11-24-2008 06:41 AM
Linq or not Linq George ASP .Net 4 11-05-2008 04:53 PM
Re: Santa Clause like you have never seen him before Jeff Griffin Wireless Networking 0 12-29-2004 02:28 PM
DataRow[] and Select(filter with a like clause) question Ron Vecchi ASP .Net 0 07-30-2003 01:04 PM
DataRow[] and Select(filter with a like clause) question Ron Vecchi ASP .Net 1 07-27-2003 01:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57