2013-01-22 38 views
0

在我們的後備數據庫中,我們有一個類型爲varbinary(max)的數據字段。使用Breeze,我們可以將數據保存在這個字段中,但是,當我們想要調用它時,我們會收到錯誤。在我們生成的模型中,該字段被映射到一個字節[]。但是,當Breeze試圖將其序列化爲一個字符串時,會引發錯誤。序列化字節時出錯[]

$id: "1", 
$type: "System.Web.Http.HttpError, System.Web.Http", 
Message: "An error has occurred.", 
ExceptionMessage: "The specified cast from a materialized 'System.String' type to the 'System.Byte[]' type is not valid.", 
ExceptionType: "System.InvalidOperationException", 
StackTrace: " at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) at System.Data.Common.Internal.Materialization.Shaper.GetColumnValueWithErrorHandling[TColumn](Int32 ordinal) at lambda_method(Closure , Shaper) at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Breeze.WebApi.ODataActionFilter.OnActionExecuted(HttpActionExecutedContext actionExecutedContext) at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception) at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__0(HttpResponseMessage response) at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass41`2.<Then>b__40(Task`1 t) at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken, Boolean runSynchronously)" 

任何幫助將是偉大的!

+0

今天晚些時候我會試着看看它。 –

回答

0

我一直無法重現這一點。

Breeze能夠將服務器端字節[]轉換爲客戶端上的字符串。只要返回一個Employee實體,您就可以在微風'DocCode'樣本中看到這個示例。 Employee類型有一個Photo屬性,它具有'byte []'的服務器端數據類型,它以'string'的形式返回給breeze客戶端。

我認爲你正在運行的是一個服務器端物化問題,您試圖將數據庫上的二進制blob物化爲字符串屬性。如果您的模型屬性被鍵入爲「String」而不是「byte []」,則會發生這種情況。

希望這會有所幫助。

相關問題