SerializationException on Catel auto create of ViewModel with EF Entity Model

折月煮酒 提交于 2019-12-12 04:58:03

问题


When Catel attempts to auto create an instance of the ViewModel class belonging to a view I get a SerializationException complaining that System.Data.Entity.DynamicProxies is not expected. The Model is an EF 6.1 Entity (inherits from ModelBase) and I am using Catel 3.9. How do I prevent this ?


回答1:


Note: this all applies to Catel 4.0 (latest prerelease versions, since that is stable and has much improvements).

Catel serializes the model for the purpose of the IEditableObject implementation. When using the Model attribute, it tries to serialize the members. You have 2 options:

  1. Use the [Model(SupportedIEditableObject = false)] (but you will lose the "automatic cancel" functionality
  2. Decorate the failing members with [ExcludeFromSerialization] or use a custom serializer modifier


来源:https://stackoverflow.com/questions/25928026/serializationexception-on-catel-auto-create-of-viewmodel-with-ef-entity-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!