473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dynamic Like clause in LINQ How?

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

Feb 2 '08 #1
1 3727
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" <no**@none.com>
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

Feb 4 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ronald S. Cook | last post by:
I've always been taught that stored procedures are better than writing SQL in client code for a number of reasons: - runs faster as is compiled and lives on the database server - is the more...
11
by: Ronald S. Cook | last post by:
I've read a few posts on the stored procedure vs dynamic sql debate. I ran a few performance test for myself and it appears to be a wash. Given that, I'm leaning toward dynamic sql mostly...
11
by: =?Utf-8?B?U3RlZmFuIFdpbGhlbG0=?= | last post by:
Hello, played a little with orcas and went into a problem by building dynamic queries. I want to build a dynamic where clause but only with parameters that are not empty =(TextBox.Text != "")....
15
by: EDBrian | last post by:
My problem is this. Our clients create different fields they want to collect and we allow them build dynamic filters, reports etc... We run some TSQL to actually create the column and all works...
9
by: =?Utf-8?B?RXZlcnQ=?= | last post by:
In my (Windows Forms) project I am using strongly typed datatables. Now I am trying to convert my 'rowfilter/group by' query logic to Linq. Most queries I can easily convert, but some I am having...
1
by: Lacutas | last post by:
Hi I'm having some problems getting a dynamic LINQ query to work on my DataSet. The idea is that a user selects certain criteria, and then the LINQ query filters through the dataset making the...
4
by: acgritt | last post by:
I am looking for some information on if it is possible/how to create a dynamic XLinq statement. I know for Linq to SQL you can do the following: var query = db.Customers. Where("City = @0 and...
4
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I am trying to set up a dynamic search using linq. I believe the syntax is correct, but cannot confirm it because when I try to cast my Session from a List<to IQueryable<>, I get a cast error...
0
by: Jay Douglas | last post by:
Hello, I've found some posts on creating dynamic WHERE clauses in LINQ to SQL using predicate builders and extending lamda expressions. One issue with these posts is all the examples only use a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.