Click here to Skip to main content
15,902,891 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionSQL Linq, IQueryable, Join and multiple contains Pin
jkirkerx26-Aug-15 10:28
professionaljkirkerx26-Aug-15 10:28 
I'm using the example provided earlier in a previous post of mine.
I want to convert this sql linq statement into a queryable, so I can adjust the take and skip,
But I can't figure out how to Join and do Multiple contains using IQueryable.

So I wrote this which works, but now I only want to take the data I need, and not the whole table that matches. I thought I needed to go IQueryable for the Take and Skip, not being to add that to the code below. If I'm wrong, please let me know.
Dim p_pageIndex as integer = 1
Dim p_pageOffset as integer = 10
Dim p_SearchQuery as String = "Kneepads"
Using context As New DBContext()

Dim pResults = _
(
    From pi In context.ProductInfo
    Join pik In context.ProductInfo_Keywords On pik.ProductID Equals pi.ProductID
    Where pik.Keywords.Contains(p_SearchQuery.Trim) _
    Or pik.Stream.Contains(p_SearchQuery.Trim) _
    Or pi.PartNumber.Contains(p_SearchQuery.Trim)
    Order By pi.PartNumber, pi.SDescription, pi.Description Descending
    Select
        pi.ProductID,
        pi.CategoryID,
        pi.SubCategoryID,
        pi.SDescription,
        pi.Description,
        pi.Thumbnail,
        pi.PartNumber,
        pi.Price    
)

In the example above, I have multiple contains from 2 tables that are Joined, I can't figure out the wording for the Join or multiple contains. the multiple OrderBy's was from a previous version in TSQL where I used ORDER By RANK
Dim context As New DBContext()
Dim items As IQueryable(Of PRODUCTINFO) = context.ProductInfo

'Sort
items = items.OrderByDescending(Function(m) m.PartNumber).OrderByDescending(Function(m) m.SDescription).OrderByDescending(Function(m) m.Description)

'Filter by Rank
items = items.Where(Function(m) m.PartNumber.Contains(p_SearchQuery))

'Get a Single Page of Data
If (p_pageIndex = 1) Then
   items = items.Take(p_pageOffset)
Else
   items = items.Skip((p_pageIndex - 1) * p_pageOffset).Take(p_pageOffset)
End If

pResults = _
   items.AsEnumerable().Select(Function(pi) New searchIndex With
   {
       pi.ProductID,
       pi.CategoryID,
       pi.SubCategoryID,
       pi.SDescription,
       pi.Description,
       pi.Thumbnail,
       pi.PartNumber,
       pi.Price
   }
)

QuestionEasy to use VB.net code with Tesseract 3.02 Pin
ezio200024-Aug-15 23:54
ezio200024-Aug-15 23:54 
AnswerRe: Easy to use VB.net code with Tesseract 3.02 Pin
Eddy Vluggen31-Aug-15 7:09
professionalEddy Vluggen31-Aug-15 7:09 
GeneralConversion from C# to VB.Net Pin
James Frimpong24-Aug-15 11:42
James Frimpong24-Aug-15 11:42 
GeneralRe: Conversion from C# to VB.Net Pin
Dave Kreskowiak24-Aug-15 13:13
mveDave Kreskowiak24-Aug-15 13:13 
QuestionExport Vb.net Datagridview to Microsoft Excel 2013 Pin
Benniiit24-Aug-15 5:09
Benniiit24-Aug-15 5:09 
AnswerRe: Export Vb.net Datagridview to Microsoft Excel 2013 Pin
Eddy Vluggen24-Aug-15 5:23
professionalEddy Vluggen24-Aug-15 5:23 
GeneralRe: Export Vb.net Datagridview to Microsoft Excel 2013 Pin
Benniiit24-Aug-15 7:54
Benniiit24-Aug-15 7:54 
GeneralRe: Export Vb.net Datagridview to Microsoft Excel 2013 Pin
Eddy Vluggen24-Aug-15 8:06
professionalEddy Vluggen24-Aug-15 8:06 
AnswerRe: Export Vb.net Datagridview to Microsoft Excel 2013 Pin
ChandraRam24-Aug-15 5:27
ChandraRam24-Aug-15 5:27 
GeneralRe: Export Vb.net Datagridview to Microsoft Excel 2013 Pin
Benniiit24-Aug-15 7:55
Benniiit24-Aug-15 7:55 
GeneralRe: Export Vb.net Datagridview to Microsoft Excel 2013 Pin
ChandraRam25-Aug-15 3:44
ChandraRam25-Aug-15 3:44 
GeneralRe: Export Vb.net Datagridview to Microsoft Excel 2013 Pin
Benniiit25-Aug-15 7:14
Benniiit25-Aug-15 7:14 
GeneralRe: Export Vb.net Datagridview to Microsoft Excel 2013 Pin
ChandraRam25-Aug-15 7:55
ChandraRam25-Aug-15 7:55 
AnswerRe: Export Vb.net Datagridview to Microsoft Excel 2013 Pin
GuyThiebaut28-Aug-15 4:39
professionalGuyThiebaut28-Aug-15 4:39 
QuestionGood freeware barcode reader library Pin
vincentvdm22-Aug-15 22:04
vincentvdm22-Aug-15 22:04 
AnswerRe: Good freeware barcode reader library Pin
Eddy Vluggen24-Aug-15 5:27
professionalEddy Vluggen24-Aug-15 5:27 
QuestionAdd a DTPicker in a Column of grid in vb6.0 Pin
Anand_@ndy21-Aug-15 19:08
Anand_@ndy21-Aug-15 19:08 
AnswerRe: Add a DTPicker in a Column of grid in vb6.0 Pin
Eddy Vluggen24-Aug-15 5:26
professionalEddy Vluggen24-Aug-15 5:26 
QuestionHow To Set H-Scrolling And V-Scrolling With AspxpivoteGrid Devexpress Pin
Member 1174163219-Aug-15 22:30
Member 1174163219-Aug-15 22:30 
AnswerRe: How To Set H-Scrolling And V-Scrolling With AspxpivoteGrid Devexpress Pin
Eddy Vluggen24-Aug-15 5:23
professionalEddy Vluggen24-Aug-15 5:23 
QuestionVB, SQL Linq, 2 Joins and multiple Groups Pin
jkirkerx18-Aug-15 8:41
professionaljkirkerx18-Aug-15 8:41 
QuestionSql Linq, Adding a group Join or Join and performing Sums, I can't figure out the Join in VB Pin
jkirkerx17-Aug-15 13:45
professionaljkirkerx17-Aug-15 13:45 
AnswerRe: Sql Linq, Adding a group Join or Join and performing Sums, I can't figure out the Join in VB Pin
Richard Deeming18-Aug-15 1:07
mveRichard Deeming18-Aug-15 1:07 
GeneralRe: Sql Linq, Adding a group Join or Join and performing Sums, I can't figure out the Join in VB Pin
jkirkerx18-Aug-15 6:37
professionaljkirkerx18-Aug-15 6:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.