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 718795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:34:06+00:00 2026-05-14T05:34:06+00:00

I am using a ms sql stored procedure to get a set of records

  • 0

I am using a ms sql stored procedure to get a set of records , when i am adding this stored procedure to my LinqToSql class and using it my repository it shows like it is returning a int value but it should be returning a set of rows. Is there some thing wrong with my stored procedure or some thing else???

ALTER PROCEDURE [dbo].[GetDocumentsAdvancedSearch]
    -- Add the parameters for the stored procedure here
      @SDI  CHAR(10) = NULL
     ,@Client CHAR(4) = NULL
     ,@AccountNumber VARCHAR(20) = NULL
     ,@Address VARCHAR(300)  = NULL
     ,@StartDate DATETIME = NULL
     ,@EndDate DATETIME = NULL
     ,@Job INT = NULL
     ,@Invoice INT = NULL
     ,@Amount MONEY = NULL
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
   -- DECLARE
    DECLARE @Sql        NVARCHAR(4000)
    DEClARE @ParamList  NVARCHAR(4000)
    DECLARE @AssociaID VARCHAR(6)
    --DECLARE 
    SET @AssociaID = 000000
    SELECT  @Sql = 'SELECT 
                    DISTINCT ISNULL(Documents.DocumentID, NULL) 
                   ,Person.Name1
                   ,Person.Name2
                   ,Person.Street1
                   ,Person.Street2
                   ,Person.CityStateZip
                   ,ISNULL(Person.ReferenceID,NULL)
                   ,ISNULL(Person.AccountNumber,NULL)
                   ,ISNULL(Person.HasSetPreferences,0)
                   ,Documents.Job
                   ,Documents.SDI
                   ,Documents.Invoice
                   ,ISNULL(Documents.ShippedDate,NULL)
                   ,ISNULL(Documents.DocumentPages,NULL)
                   ,Documents.DocumentType
                   FROM
                   Person
                   LEFT OUTER JOIN Documents ON Person.PersonID = Documents.PersonID
                   LEFT OUTER JOIN DocumentType ON Documents.DocumentType = DocumentType.DocumentType
                   LEFT OUTER JOIN Addresses   ON Person.PersonID = Addresses.PersonID
                   WHERE '                   

   IF NOT(@SDI IS NULL)
   SELECT @Sql = @Sql + ' Documents.SDI IN ('+@sdi+')' 
   IF NOT(@Client IS NULL)
   SELECT @Sql = @Sql + ' OR (Person.AssociationID = ' + @AssociaID + ' AND Person.Client ='+ @Client+')'   
   IF NOT(@AccountNumber IS  NULL)
   SELECT @Sql = @Sql + ' AND Person.AccountNumber LIKE ' + @AccountNumber
   IF NOT(@Address IS  NULL)
   SELECT @Sql = @Sql + ' AND Person.Name1 LIKE' + @Address + 'AND Person.Name2 LIKE' + @Address + ' AND Person.Street1 LIKE' + @Address + ' AND Person.Street2 LIKE' + @Address + ' AND Person.CityStateZip LIKE' + @Address
   IF NOT(@StartDate IS  NULL)
   SELECT @Sql = @Sql + ' AND Documents.ShippedDate >=' +@StartDate
   IF NOT(@EndDate IS NULL)
   SELECT @Sql = @Sql + ' AND Documents.ShippedDate <=' +@EndDate
   IF NOT(@Job IS NULL)
   SELECT @Sql = @Sql + ' AND Documents.Job =' +@Job
   IF NOT(@Invoice IS NULL)
   SELECT @Sql = @Sql + ' AND Documents.Invoice =' +@Invoice
   IF NOT(@Amount IS NULL)
   SELECT @Sql = @Sql + ' AND Documents.Amount =' +@Amount
    -- Insert statements for procedure here
    --PRINT @Sql
    SELECT @ParamList = '@Psdi CHAR(10),@PClient CHAR(4),@PAccountNumber VARCHAR(20),@PAddress VARCHAR(300),@PStartDate DATETIME ,@PEndDate DATETIME,@PJob INT,@PInvoice INT,@PAmount Money '
    EXEC SP_EXECUTESQL @Sql,@ParamList,@Sdi,@Client,@AccountNumber,@Address,@StartDate,@EndDate,@Job,@Invoice,@Amount
    --PRINT @Sql

END



[Function(Name="dbo.GetDocumentsAdvancedSearch")]
        public int GetDocumentsAdvancedSearch([Parameter(Name="SDI", DbType="Char(10)")] string sDI, [Parameter(Name="Client", DbType="Char(4)")] string client, [Parameter(Name="AccountNumber", DbType="VarChar(20)")] string accountNumber, [Parameter(Name="Address", DbType="VarChar(300)")] string address, [Parameter(Name="StartDate", DbType="DateTime")] System.Nullable<System.DateTime> startDate, [Parameter(Name="EndDate", DbType="DateTime")] System.Nullable<System.DateTime> endDate, [Parameter(Name="Job", DbType="Int")] System.Nullable<int> job, [Parameter(Name="Invoice", DbType="Int")] System.Nullable<int> invoice, [Parameter(Name="Amount", DbType="Money")] System.Nullable<decimal> amount)
        {
            IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), sDI, client, accountNumber, address, startDate, endDate, job, invoice, amount);
            return ((int)(result.ReturnValue));
        }
  • 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-05-14T05:34:06+00:00Added an answer on May 14, 2026 at 5:34 am

    My guess would be that since the SQL is dynamic, LINQ isn’t able to determine exactly what the procedure will be returning.

    Best workaround for this would probably be to just hand-edit the .dbml file

    ETA: If you aren’t sure what to put in the .dbml file, another option might be to “trick” it into figuring out what you are returning from your sproc by putting some SQL inside a block that will never actually execute in practice:

    IF ( FALSE )
    BEGIN
      SELECT 
      DISTINCT ISNULL(Documents.DocumentID, NULL) 
      ,Person.Name1
      ,Person.Name2
      ,Person.Street1
      ,Person.Street2
      ,Person.CityStateZip
      ,ISNULL(Person.ReferenceID,NULL)
      ,ISNULL(Person.AccountNumber,NULL)
      ,ISNULL(Person.HasSetPreferences,0)
      ,Documents.Job
      ,Documents.SDI
      ,Documents.Invoice
      ,ISNULL(Documents.ShippedDate,NULL)
      ,ISNULL(Documents.DocumentPages,NULL)
      ,Documents.DocumentType
      FROM
       Person
       LEFT OUTER JOIN Documents ON Person.PersonID = Documents.PersonID
       LEFT OUTER JOIN DocumentType ON Documents.DocumentType = DocumentType.DocumentType
       LEFT OUTER JOIN Addresses   ON Person.PersonID = Addresses.PersonID
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a paged search stored procedure using SQL Server 2005. It takes a
I am using SQL server 2000. I have a stored procedure sitting on machine
When using Linq to SQL and stored procedures, the class generated to describe the
I have a huge database with 100's of tables and stored procedures. Using SQL
I am using MS SQL Server 2005, I have dates stored in epoch time
I'm using ASP.NET, with session state stored out of process in SQL Server. When
I have been spoiled by either using sql server to store data, or using
I'm using nhibernate to store some user settings for an app in a SQL
I'm using C# and .NET 3.5. I need to generate and store some T-SQL
Using SQL Server, how do I split a string so I can access item

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.