Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Linq, query and then take result to query again

SQL Linq, query and then take result to query again

Scheduled Pinned Locked Moved Database
databaselinqcsharp
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    So I thought I was getting this down now. In my original code, I used 1 function to get the name, and another function to get the record results. So I rewrote it Linq, But I'm not quite getting how it works. So the first query called contributor returns a result that looks like SQL sort of, and says to expand to see the results. The 2nd query does the same thing, and the pValue for the record count is non zero, and triggers an exception of non zero. So I'm missing something on the concept here, and can't figure it out. I shortened the sample for easier reading.

    Public Shared Function load_movieContributor_array( _
    ByVal pMovieID As Integer,
    ByVal pPageIndex As Integer,
    ByVal pPageSize As Integer,
    ByRef pResults As IEnumerable(Of MovieIndex)) As Integer

        Dim pValue As Integer = 0
    
        Dim context As New MoviesContext()
        Dim contributor = \_
            (From m In context.Movies
            Where m.MovieID = pMovieID
            Select m.MovieContributor)
    
        Dim movies As IQueryable(Of Movies) = context.Movies
        movies = movies.Where(Function(m) m.MovieContributor = contributor)
        movies = movies.OrderBy(Function(m) m.MovieName)
    
        'Get a Single Page of Data
        If (pPageIndex = 1) Then
            movies = movies.Take(pPageSize)
        Else
            movies = movies.Skip((pPageIndex - 1) \* pPageSize).Take(pPageSize)
        End If
    
        pResults = \_
            movies.AsEnumerable().Select(Function(item) New MovieIndex With
            {
                .MovieID = item.MovieID,
                'More columns .....
        })
    
        pValue = pResults.Count()
    
        Return pValue
    
    End Function
    
    J 1 Reply Last reply
    0
    • J jkirkerx

      So I thought I was getting this down now. In my original code, I used 1 function to get the name, and another function to get the record results. So I rewrote it Linq, But I'm not quite getting how it works. So the first query called contributor returns a result that looks like SQL sort of, and says to expand to see the results. The 2nd query does the same thing, and the pValue for the record count is non zero, and triggers an exception of non zero. So I'm missing something on the concept here, and can't figure it out. I shortened the sample for easier reading.

      Public Shared Function load_movieContributor_array( _
      ByVal pMovieID As Integer,
      ByVal pPageIndex As Integer,
      ByVal pPageSize As Integer,
      ByRef pResults As IEnumerable(Of MovieIndex)) As Integer

          Dim pValue As Integer = 0
      
          Dim context As New MoviesContext()
          Dim contributor = \_
              (From m In context.Movies
              Where m.MovieID = pMovieID
              Select m.MovieContributor)
      
          Dim movies As IQueryable(Of Movies) = context.Movies
          movies = movies.Where(Function(m) m.MovieContributor = contributor)
          movies = movies.OrderBy(Function(m) m.MovieName)
      
          'Get a Single Page of Data
          If (pPageIndex = 1) Then
              movies = movies.Take(pPageSize)
          Else
              movies = movies.Skip((pPageIndex - 1) \* pPageSize).Take(pPageSize)
          End If
      
          pResults = \_
              movies.AsEnumerable().Select(Function(item) New MovieIndex With
              {
                  .MovieID = item.MovieID,
                  'More columns .....
          })
      
          pValue = pResults.Count()
      
          Return pValue
      
      End Function
      
      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      Public Shared Function load_movieContributor_array( _
      ByVal pMovieID As Integer,
      ByVal pPageIndex As Integer,
      ByVal pPageSize As Integer,
      ByRef pResults As IEnumerable(Of MovieIndex)) As Integer

          Dim pValue As Integer = 0
      
          Dim context As New MoviesContext()
          Dim cResults = \_
              (From m In context.Movies
              Where m.MovieID = pMovieID
              Select m.MovieContributor).SingleOrDefault()
      
          Dim m\_contributor As String = cResults
      
          Dim movies As IQueryable(Of Movies) = context.Movies
          movies = movies.Where(Function(m) m.MovieContributor = m\_contributor)
          movies = movies.OrderBy(Function(m) m.MovieName)
      
          'Get a Single Page of Data
          If (pPageIndex = 0) Then
              movies = movies.Take(pPageSize + 1)
          Else
              movies = movies.Skip((pPageIndex + 1) \* pPageSize).Take(pPageSize)
          End If
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups