2016-03-08 66 views
-2

我有以下DB調用通過Web API製作:的Web API引發未處理的異常錯誤

public IEnumerable<PogStoreData> GetStoreSetData(string FloorplanIdList, string PogIdList, string PogName, string Season, string Version, 
      string PogStatusList, Nullable<DateTime> IssueDate, Nullable<DateTime> StartDate, Nullable<DateTime> LiveDate, 
      Nullable<DateTime> ExpirationDate, string PogMoveTypeList) 
{ 
    // Create the parameters collection 
    var parameters = new Collection<SqlParameter>(); 

    // Add each parameter. Entity will not work without all params in the correct order 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@fpIdList", string.IsNullOrEmpty(FloorplanIdList) ? null : FloorplanIdList, -1)); 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@pogIdList", string.IsNullOrEmpty(PogIdList) ? null : PogIdList, -1)); 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@pogName", string.IsNullOrEmpty(PogName) ? null : PogName, 100)); 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@season", string.IsNullOrEmpty(Season) ? null : Season, -1)); 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@version", string.IsNullOrEmpty(Version) ? null : Version, -1)); 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@pogStatusList", string.IsNullOrEmpty(PogStatusList) ? null : PogStatusList, 10)); 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@issueDate", IssueDate.HasValue ? IssueDate.Value.ToShortDateString() : null, 20)); 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@startDate", StartDate.HasValue ? StartDate.Value.ToShortDateString() : null, 20)); 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@liveDate", LiveDate.HasValue ? LiveDate.Value.ToShortDateString() : null, 20)); 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@expirationDate", ExpirationDate.HasValue ? ExpirationDate.Value.ToShortDateString() : null, 20)); 
    parameters.Add(StoredProcedureParameterBuilder.StringParam("@pogMoveList", string.IsNullOrEmpty(PogMoveTypeList) ? null : PogMoveTypeList, 10)); 

    return SelectList<PogStoreData>("spc.SPA_get_store_set_data_by_criteria", parameters); 
} 

以下是對的SelectList代碼:

private IEnumerable<T> SelectList<T>(string inStoredProcedure, ICollection<SqlParameter> inParameters) 
{ 
    string paramNames = string.Join(",", inParameters.Select(parameter => parameter.ParameterName).ToList()); 
    string sqlString = inStoredProcedure + " " + paramNames; 
    object[] paramValues = inParameters.Cast<object>().ToArray(); 

    if (paramValues.Length > 0) 
     return this.Database.SqlQuery<T>(sqlString, paramValues).ToList(); 
    else 
     return this.Database.SqlQuery<T>(sqlString).ToList(); 
} 

但是,當我只爲PogStatus列表傳遞價值我收到以下錯誤: 由於物化值爲空,因此類型爲「System.Double」的類型轉換失敗。 我在SqlQuery(sqlString).ToList()語句中得到上述錯誤。 我不知道如何解決這個問題。請幫忙。

回答

1

最可能的原因是您的PogStoreData類型中有double類型的字段/屬性,但查詢返回null。

嘗試直接在數據庫中執行此存儲過程(例如,在Management Studio中),並將結果與​​您希望接收的數據進行比較。

相關問題