Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8213635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:11:13+00:00 2026-06-07T11:11:13+00:00

I am new to Linq and trying to convert this SQL Server stored procedure

  • 0

I am new to Linq and trying to convert this SQL Server stored procedure into Linq, I am building a Silverlight business app and need to call on this procedure to return a grid of results.

I have multiple parameters that the users can use to search for particular pieces. They narrow down their search through the UI and when they hit the search button, the code behind takes all the arguments and sends it to my Linq service, which then needs to call on the stored procedure.

Here is the stored procedure.

ALTER PROCEDURE dbo.spSearchResults
@PieceType      nvarchar(6) =  '',
@FileType       nvarchar(3) = '',
@Market     nvarchar(6) = '',
@PieceNumber        nvarchar(6) = '',
@Header1    nvarchar(50) = '',
@Header2    nvarchar(50) = '',
@Header3    nvarchar(50) = '',
@Header4    nvarchar(50) = '',
@JobNumber      nvarchar(50)=' ',
@bShowInActive  BIT = 0,
@UDAC1      nvarchar(50) = '',
@UDAC2      nvarchar(50) = '',
@UDAC3      nvarchar(50) = '',
@UDAC4      nvarchar(50) = ''   
AS
BEGIN
SET NOCOUNT ON

SELECT J.* 
FROM Job J
  LEFT JOIN JobHeading H1 (NOLOCK) ON J.[JobNumber] =  H1.[JobID]
  LEFT JOIN JobHeading H2 (NOLOCK) ON J.[JobNumber] =  H2.[JobID]
  LEFT JOIN JobHeading H3 (NOLOCK) ON J.[JobNumber] =  H3.[JobID]
  LEFT JOIN JobHeading H4 (NOLOCK) ON J.[JobNumber] =  H4.[JobID]
  LEFT JOIN JobUDAC udac1 (NOLOCK) ON J.[JobNumber] = udac1.[JobID]
  LEFT JOIN JobUDAC udac2 (NOLOCK) ON J.[JobNumber] = udac2.[JobID]
  LEFT JOIN JobUDAC udac3 (NOLOCK) ON J.[JobNumber] = udac3.[JobID]
  LEFT JOIN JobUDAC udac4 (NOLOCK) ON J.[JobNumber] = udac4.[JobID]
WHERE ((@PieceType = '') OR (PieceType = @PieceType))
  AND ((@FileType = '') OR (FileType = @FileType))
  AND ((@Market = '') OR (Market = @Market))
  AND ((@PieceNumber = '') OR (PieceNumber = @PieceNumber))
  AND ((@JobNumber = '') OR (JobNumber = @JobNumber))
  AND (J.IsActive=1 OR @bShowInActive = 1)
  AND (((@Header1 = '' AND @Header2 = '' AND @Header3 = '' AND @Header4 = '') OR 
        H1.HeadingRowID = @Header1)
    OR (--@Header2=0 OR 
        H2.HeadingRowID = @Header2 )
    OR (--@Header3=0 OR 
        H3.HeadingRowID = @Header3)
    OR (--@Header4=0 OR 
        H4.HeadingRowID = @Header4))
  AND (((@UDAC1 = '' AND @UDAC2 = '' AND @UDAC3 = '' AND @UDAC4 = '') OR 
        udac1.UDACRowID = @UDAC1)
    OR (--@Header2=0 OR 
        udac2.UDACRowID = @UDAC2 )
    OR (--@Header3=0 OR 
        udac3.UDACRowID = @UDAC3)
    OR (--@Header4=0 OR 
        udac4.UDACRowID = @UDAC4))

In Linq I found that there are certain conversions to do and this is my attempt.

var query = from j in Job
                    join JobHeading H1 in Job on headingRowID1 equals H1
                    join JobHeading H2 in Job on headingRowID2 equals H2
                    join JobHeading H3 in Job on headingRowID3 equals H3
                    join JobHeading H4 in Job on headingRowID4 equals H4
                    join JobUDAC udac1 in Job on udacRowID1 equals udac1
                    join JobUDAC udac2 in Job on udacRowID2 equals udac2
                    join JobUDAC udac3 in Job on udacRowID3 equals udac3
                    join JobUDAC udac4 in Job on udacRowID4 equals udac4
                    join PieceType in db on piece equals PieceType
                    join JobFileType in db on filetype equals JobFileType
                    join Book in db on market equals Book
                    join PieceNumber in db on pieceNumber equals PieceNumber
                    join JobNumber in db on jobNumber equals JobNumber
                    join Job in db on FindJobs equals db
                    where ((piece = string.Empty) || (PieceType = piece))
                      && ((filetype = string.Empty) || (JobFileType = filetype))
                      && ((market = string.Empty) || (Book = market))
                      && ((pieceNumber = string.Empty) || (PieceNumber = pieceNumber))
                      && ((jobNumber = string.Empty) || (JobNumber = jobNumber))
                      && (showInActive = true)
                      && ((((headingRowID1 = string.Empty) + (headingRowID2 = string.Empty) + (headingRowID3 = string.Empty) + (headingRowID4 = string.Empty)) ||
                            H1.HeadingRowID = headingRowID1)
                        || (H2.HeadingRowID = headingRowID2)
                        || (H3.HeadingRowID = headingRowID3)
                        || (H4.HeadingRowID = headingRowID4))
                      && ((((udacRowID1 = string.Empty) + (udacRowID2 = string.Empty) + (udacRowID3 = string.Empty) + (udacRowID4 = string.Empty)) ||
                            udac1.UDACRowID = udacRowID1)
                        || (udac2.UDACRowID = udacRowID2)
                        || (udac3.UDACRowID = udacRowID3)
                        || (udac4.UDACRowID = udacRowID4))
                    select j.Job;
        return query;

However, the beginning ‘Job’ has an error, and says ‘could not find an implementation … ‘join’ not found’ Can anyone help translate? Or offer a better way to call the stored procedure with the code behind? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:11:15+00:00Added an answer on June 7, 2026 at 11:11 am

    You can add your store procedure to the entity context and call it as it were a method.

    To accomplish this, you have to add the store procedure to the entity model. You don’t say how are you building the model or what version of EF you are using, but I assume you can just go ahead and update the model from the DB and add the store procedure.

    Once you have the SP in the model you have to turn the SP into a Function Import. The way you do this is by navigating to the store procedure in the Model Browser, right click the SP icon and select “Add function import”. Because you are returning a complex result set, I suggest you build a Complex Type, which you will use as the result type of the SP. To create a Complex Type in the Add Function Import dialog click the “Get Column Information” button. That will present the return values of your SP, so you can create a new Complex Type by clicking the “Create New Complex Type” button. Give it a name and click OK. Your function import is now under “Function Imports” in the Model Browser.

    The way you call you function import method is:

    var result = context.spSearchResults(Your list of parameters...);
    

    This executes the SP, and “result” should give you a list of objects of the type of your complex type.

    A couple of references:

    http://msdn.microsoft.com/en-us/library/bb896231.aspx

    http://msdn.microsoft.com/en-us/library/ee534438.aspx

    Just to be complete: other way you can add a complex type is: in Model Browser navigate to “Complex Types”, right click and select “Create Complex Type”. There you have to define a complex type that has the same properties (names and types) of the result set of your SP. In the dialog box select Complex in the “Returns a Collection of”,

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert this sql into my LINQ query and am having
I am trying to convert this SQL to linq syntax, but I'm having some
I am attempting to convert a SQL stored procedure to LINQ to do some
New to MVC3 Razor - linq to sql having spent some time trying to
I am trying to convert a SQL query to LINQ. Somehow my count(distinct(x)) logic
I have a SQL Statement that I am trying to convert to a LINQ
I am new to linq.. this is what i am trying to do bool
I am trying to convert following SQL query to linq; select Or.Amount, Usr.Name, Usr.Email
I am trying to convert some of my stored procedures to Linq and am
I am new to this LINQ field and one thing am trying to do.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.