Identifying NHibernate proxy classes

后端 未结 7 1972
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 06:53

I\'m not an NHibernate user; I write a serialization utility library. A user has logged a feature-request that I should handle NHibernate proxy classes, treating them the sa

相关标签:
7条回答
  • 2020-11-28 07:47

    NHibernate creates (proxy) sub classes of the original entities at runtime to be able to do lazy loading. It is only able to do this because you are forced to mark all properties as "virtual". I can't think of how you could detect that an object is a proxy as opposed to any other kind of sub classing - certainly not in a generic way. I can only presume that your code is throwing an exception in this case because the actual class that is being (de-)serialized isn't marked as being serializable. I think the only thing you can do is loosen up your validation or allow serialization of a sub class if it overrides all properties of its base class.

    Deserializing to the original type will be fine.

    0 讨论(0)
提交回复
热议问题