الأربعاء، 10 يونيو 2015

StoredProcedure - get sql data by coalesce parameters


ALTER PROCEDURE [dbo].[GetAllSessionComments]
@SessionId int=NULL,
@UserId int=NULL
AS
IF @SessionId=0 BEGIN SET @SessionId=NULL END
IF @UserId=0 BEGIN SET @UserId=NULL END

SELECT * FROM SessionComments
WHERE SessionComments.SessionId=COALESCE(@SessionId,SessionComments.SessionId)
AND SessionComments.UserId=COALESCE(@UserId,SessionComments.UserId)
return


Code Behind :
ICollection<SessionComments> comments = _entities.GetAllSessionComments(_session.SessionId, null).ToList();

ليست هناك تعليقات:

إرسال تعليق