Given:
- I'm trying to create a REST API using ASP.NET MVC.
- I'm using NHibernate in my data access layer.
Problem:
- I'm can't XmlSerialize ISet properties.
I get errors like the following:
Cannot serialize member
[namespace].[entity].[property] of
type
Iesi.Collections.Generic.ISet`1[[namespace].[entity],
[assembly], Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null]]
because it is an interface.
- I'll freely admit: I'm very new to NHibernate.
- So I don't know what my options are.
- I believe that I need to use a set as opposed to a bag because my collections contain unique items.
- When I converted the ISet properties to HashedTable properties (i.e. a concrete class), I got errors like the following:
You must implement a default accessor
on
Iesi.Collections.Generic.HashedSet`1[[namespace].[entity],
[assembly],
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]] because it
inherits from ICollection.
My questions:
- What should I do to remedy this situation?
- Should I implement default accessors in all of my entity classes?
- If so, is there a recommended pattern for doing so?
- Should I implement default accessors in all of my entity classes?
As a sidenote, I tried Googling for help.
– I don't think this is a new problem.
Best Answer
NHibernate serialization has been treated a lot on stackoverflow. See:
Bottom line: use DTOs.