Clicky

I have a search form, and depending on what selections were made in the form, I want to build my LINQ query. I do this with SQL, but don't know how to do it with LINQ.

I'm attaching an example of how I build the query string now. Could you please show me an example of how I might go about building a LINQ query the same way?

thanks.
 Public Function GetBySearchCriteriaQuery(Optional ByVal CMSContentId As String = "", _                                         Optional ByVal CMSTopicCode As String = "", _                                           Optional ByVal CMSStatusCode As Integer = INVALID_ID) As String              Dim sql As String = String.Empty             Try                  Dim whereClause As New StringBuilder()                  If CMSContentId <> String.Empty And CMSContentId <> INVALID_ID.ToString Then                     If whereClause.ToString() = String.Empty Then                         whereClause.AppendLine(" WHERE ")                     Else                         whereClause.AppendLine(" AND ")                     End If                     whereClause.AppendLine(String.Format(" CMSContentId IN ({0}) ", CMSContentId))                 End If                   If CMSTopicCode <> String.Empty And CMSTopicCode <> INVALID_ID.ToString Then                     If whereClause.ToString() = String.Empty Then                         whereClause.AppendLine(" WHERE ")                     Else                         whereClause.AppendLine(" AND ")                     End If                     whereClause.AppendLine(String.Format(" CMSContent.CMSContentId IN (Select CMSContentID from CMSTopic where CMSTopicCode IN ({0})) ", CMSTopicCode))                 End If                   If CMSStatusCode <> INVALID_ID Then                     If whereClause.ToString() = String.Empty Then                         whereClause.AppendLine(" WHERE ")                     Else                         whereClause.AppendLine(" AND ")                     End If                     whereClause.AppendLine(String.Format(" CMSStatusCode = {0} ", CMSStatusCode))                 End If                  sql = String.Format("SELECT CMSContent.*, CatCode.ListValueName FROM {0} " & _                                " LEFT OUTER JOIN ListValue AS CatCode ON CatCode.ListValueId = CMSContent.CMSCategoryCode " & _                                 " {1} " & _                                 " Order By {2} ", Me.DatabaseTableName, whereClause.ToString(), Me.OrderBy)              Catch ex As Exception              End Try              Return sql          End Function                             
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: 

Select allOpen in new window

asked 12/10/2011 01:01

BobCSD's gravatar image

BobCSD ♦♦


2 Answers:
First link was spot on! the other two... eh.

thanks!
link

answered 2011-12-11 at 09:47:51

BobCSD's gravatar image

BobCSD

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

Asked: 12/10/2011 01:01

Seen: 322 times

Last updated: 12/11/2011 01:55