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));
}