实体框架 T4 POCO 对象在 WCF 中引发异常
这些对象具有 ICollection<> 类型的集合。
如果我将对象图从客户端传递到服务器,它会引发以下异常:
System.NotSupportedException was unhandled by user code
Message=Collection was of a fixed size.
Source=mscorlib
这是在 T4 模板生成的修复代码中发生的。看来集合正在服务器上作为数组反序列化,因此无法修改。有没有办法指定序列化器应使用的类型?
These objects have collections of type ICollection<>
If I pass an object graph from client to server it throws the following exception:
System.NotSupportedException was unhandled by user code
Message=Collection was of a fixed size.
Source=mscorlib
Which is occurs in the fixup code the T4 template has generated. It seems the collections are being deserialized on the server as arrays and so can't be modified. Is there a way to specify the type the serializer should use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我强烈建议您不要在服务边界上使用 POCO 类。创建一组单独的类来对要通过线路发送和接收的数据(数据传输对象 - DTO)进行建模,并使用诸如 automapper< /a> 在 DTO 和 POCO 类之间移动数据
本质上,您最终将服务的使用者与服务的内部概念模型联系起来,这意味着您在更改实现方面受到限制,因为您需要避免破坏客户端
I would strongly recommend that you don't use the POCO classes on your service boundary. Create a separate set of classes to model the data you want to send and receive across the wire (Data Transfer Objects - DTOs) and use a tool like automapper to move data between the DTOs and your POCO classes
Essentially you end up tying the consumers of your service to your service's internal conceptual model which means you become constrained in changing your implementation because you need to avoid breaking your clients
尝试使用以下属性
如果这不起作用,也许可以尝试使用
IList
(如果您的情况可行)Try using the following attribute
If that doesn't work, perhaps try using
IList<T>
if that is possible in your situation