Hello Everyone,
Below is my Store-procedure.
ALTER PROC usp_module_assigned_details
(
@CounrtyID BIGINT = NULL,
@ModuleID BIGINT = NULL,
@case INT
)
AS BEGIN
IF @case = 1 -- Select assigned module to the country
BEGIN
SELECT ModuleID
FROM Country_Module_Assign
WHERE CountryID=@CounrtyID
END
END
I use this type style of store-procedure with ado.net and it works fine, without any issue. [I use more than 50 store procedure in my previous project. All of them work perfectly].
But when I try to use store-procedure with entity framework, it doesn't tale my variable (@ModuleID BIGINT = NULL), AS NULL. I already defined ion in my declaration part.
When I execute it by giving @CountryID and @case
exec usp_module_assigned_details 221,1
It says Procedure or function 'usp_module_assigned_details' expects parameter '@case', which was not supplied.
But when I execute like below
exec usp_module_assigned_details 221 ,NULL,1
It executes perfectly.
My question is that when I already defines @ModuleID BIGINT AS NULL, whey it is demanding it.
Below is my EF Code.
int country_id = Convert.ToInt32(Session["USER-Country"].ToString());
SqlParameter param1 = new SqlParameter("@CounrtyID", Convert.ToInt32(country_id));
SqlParameter param2 = new SqlParameter("@case", 1);
var ModuleList = db.Database.SqlQuery<ModuleModel>("usp_module_assigned_details @CounrtyID,@case", param1, param2).ToList();
ViewBag.AssignedModules = ModuleList;
return ModuleList;Please Suggest.