Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

asp.net mvc - NHibernate: How do I XmlSerialize an ISet<T>?

Given:

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?

As a sidenote, I tried Googling for help.
- I don't think this is a new problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...