EntityFramework-存储过程(从Null到Int32)

时间:2018-06-20 08:10:10

标签: c# entity-framework stored-procedures

我正在尝试执行存储过程以填充我的实例。

{
    SqlParameter[] sqParams = new SqlParameter[]
    {
        new SqlParameter{ParameterName = "@rn", Value = firm.Rn, Direction = System.Data.ParameterDirection.Input},
        new SqlParameter{ParameterName = "@startDate", Value = startDate, Direction = System.Data.ParameterDirection.Input},
        new SqlParameter{ParameterName = "@endDate", Value = endDate, Direction = System.Data.ParameterDirection.Input},
        new SqlParameter{ParameterName = "@spmo", Value = firm.Bkm == 3 ? 0 : 1, Direction = System.Data.ParameterDirection.Input},
        new SqlParameter{ParameterName = "@pmo", Value = 0, Direction = System.Data.ParameterDirection.Input}
    };

    return _context.Database.SqlQuery<SupportTypeBased>("s_FirmSupportAnalysis @rn, @startDate, @endDate, @spmo, @pmo", sqParams).ToList();
}

还有我的返回实体。

public class SupportTypeBased : IDTOEntity
    {
        public string RECTYPE { get; set; }
        public int MCOUNT { get; set; }
        public int DCOUNT { get; set; }
    }

查询数据库结果。 enter image description here

如您所见,问题是数据库为我的类中的“ Int32 ”类型的“ DCOUNT”属性返回“ NULL”。那么我该如何说,如果value为null,将其设置为0,而无需请勿触摸我的存储过程,或者请勿将属性类型更改为 Int?

0 个答案:

没有答案