没有将存储过程结果导入控制器但执行过程

时间:2018-03-29 07:14:55

标签: c# asp.net sql-server entity-framework

我使用此处显示的程序来计算年龄

ALTER PROCEDURE [dbo].[sp_GetVotersByAge]   
    @lokSabhaID bigint = null, 
    @vidhanSabhaID bigint = null,
    @wardID bigint = null,  
    @year int     
AS 
BEGIN
    IF (@vidhanSabhaID IS NULL AND @wardID IS NULL)     
    BEGIN
        SELECT COUNT(voterID) AS 'Age Between 18 and 30' 
        FROM voterList          
        WHERE (@year - (datepart(year, dateOfBirth))) BETWEEN 18 AND 30 
          AND lokSabhaConstituencyID = @lokSabhaID  

        SELECT COUNT(voterID) AS 'Age Between 30 and 50' 
        FROM voterList          
        WHERE (@year - (datepart(year, dateOfBirth))) BETWEEN 30 AND 50 
          AND lokSabhaConstituencyID = @lokSabhaID

        SELECT COUNT(voterID) AS 'Age Above 50' 
        FROM voterList          
        WHERE (@year - (datepart(year, dateOfBirth))) > 50 
          AND lokSabhaConstituencyID = @lokSabhaID

        IF (@lokSabhaID IS NULL AND @wardID IS NULL)    
        BEGIN
            EXEC @return_value = [dbo].[sp_GetVotersByAge]  
                                        @lokSabhaID = 1,
                                        @vidhanSabhaID = NULL,      
                                        @wardID = NULL,         
                                        @year = 2000

下面是我调用存储过程的控制器方法。

使用

设置Null值
 var vidhanSabhaID_ = new SqlParameter("@vidhanSabhaID", SqlString.Null); 

var result = uow.getAgeReport_.SQLQuery<sp_GetVotersByAge_Result>("sp_GetVotersByAge @lokSabhaID, @vidhanSabhaID, @wardID, @year", lokSabhaID_,
 vidhanSabhaID_, wardID_, year_).FirstOrDefault();

我的模特是:

public class sp_GetVotersByAge_Result
{
         public int AgeBetween18and30 { get; set; }
         public int AgeBetween30and50 { get; set; }
         public int AgeMoreThan50 { get; set; }
}

当我在SQL Server中执行它时,该过程有效。但是当我在Entity Framework

中执行它时,我没有得到任何结果

0 个答案:

没有答案