How to implement correctly IUserType?

后端 未结 2 1213
清酒与你
清酒与你 2020-12-03 10:25

I need to create a custom type for NHibernate by writing a new mapper class that implements IUserType. While it is relatively straightforward to override most o

相关标签:
2条回答
  • 2020-12-03 10:51

    You may want to check out this article. It is a good example of how to implement the IUserType interface.

    0 讨论(0)
  • 2020-12-03 10:52

    Have a look at how Ritesh Rao has done this in his NCommon framework:

    The MoneyUserType implements a base class called CompositeUserTypeBase

    There's more detail in the comments but to summarize:

    • DeepCopy - should return a deep copy of the persistent state, stopping at entities and at collections
    • Disassemble - transforms the object into its 'cacheable' representation (i.e. associations must be cached as identifier values)
    • Assemble - reconstructs an object from the cacheable representation

    It's explained in a lot more detail here

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