2
由於問題的標題國強類型的查詢參數的時候,我得到Specified cast is not valid
例外,即使我的存儲過程返回int
和DateTime
和我的類定義它一樣。小巧玲瓏的投擲無效轉換異常與使用Sybase ASE的
public class Foo
{
public int Id {get; set;}
public DateTime CreatedDate {get; set;}
}
當我執行此查詢:
變種結果= connection.Query( 「spGetFoo」,命令類型:CommandType.StoredProcedure);
我得到以下兩種例外:
InvalidCastException: Specified cast is not valid.
DataException: Error parsing column 1 (Id=1 - Decimal)
InvalidCastException: Specified cast is not valid.
DataException: Error parsing column 2 (CreatedDate=Mar 7 2012 5:52:08:276PM - String)
如果我修改的Foo
性質從int
到decimal
和DateTime
到string
得當填充值。但是,這引入了一個額外的步驟,即定義另一個包含正確變量類型的類,然後將Foo
映射到新類。
我也嘗試通過Dapper源代碼中的GetTypeDeserializer
來查看發生了什麼,但我對IL排放不是很熟悉。
你肯定spGetFoo收益爲int和日期時間?你能顯示SQL和可能的列定義嗎? – 2012-03-13 13:54:38
當然很高興看到Stored Proc .... – 2012-03-16 14:08:44