序列化byte []时出错

时间:2013-01-22 19:30:16

标签: breeze

在我们的支持数据库中,我们有一个varbinary(max)类型的数据字段。使用Breeze,我们可以在此字段中保存数据,但是,当我们想要将其调回时,我们会收到错误。在我们生成的模型中,字段被映射到byte []。但是当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)"

任何帮助都会很棒!

1 个答案:

答案 0 :(得分:0)

我无法重现这一点。

Breeze能够获取服务器端byte []并将其转换为客户端上的字符串。每当返回Employee实体时,您都可以在微风'DocCode'示例中看到这样的示例。 Employee类型具有Photo属性,其服务器端数据类型为'byte []',并以“字符串”的形式返回给breeze客户端。

我认为您遇到的是服务器端实现问题,您尝试将数据库上的二进制blob实现为字符串属性。如果您的模型属性被键入为'String'而不是'byte []',则会发生这种情况。

希望这有帮助。

相关问题