Lesser-Known NHibernate Features: Serializable Values
If you want to store anything in a property of an entity, you can declare it as Object or dynamic; as long as you set it to a value of a serializable type, as supported by BinaryFormatter, you’re good! You can even change the value afterwards to a different type, and it will be saved.
You map it like this, in mapping by code:
1: ca.Property(x => x.Payload, x =>
2: {
3: x.Column("`payload`");
4: x.NotNullable(false);
5: x.Type(NHibernateUtil.Serializable);
6: });
Where the class should have a property of type Object or dynamic:
1: //public virtual Object Payload
2: public virtual dynamic Payload { get; set; }
NHibernate will return the same object type and all of its contents anytime you retrieve it.
Try that in other persistence frameworks!