To receive entities from database I created the class with virtual members. When I received an entity from database I cant serialize it and I can't send it by web service. Is there any any ways to solve this problem?
Asked
Active
Viewed 78 times
0
-
Please post some sample code here – oleksii Feb 14 '12 at 13:02
-
I found that post http://stackoverflow.com/questions/1190718/how-do-i-serialize-all-properties-of-an-nhibernate-mapped-object it's like my situation – Max Kilovatiy Feb 14 '12 at 13:06
1 Answers
0
Do your typical setup...
public class MyTable
{
public virtual int ID {get;set;}
public virtual string Name {get;set;}
}
I have a special response class I wrap my data in when responding to a web service call
using System.Xml.Serialization;
...
[XmlInclude(typeof(Response))]
[XmlInclude(typeof(MyTable))]
public class Response
{
public virtual bool Success {get;set;}
public virtual MyTable MyTable {get;set;}
}
The "[XmlInclude(typeof(Response))]" and "[XmlInclude(typeof(MyTable))]" causes the table "MyTable" to serialize as XML within "Response". If you reference "MyTable" as a list you will need "[XmlInclude(typeof(List))]".
I hope this helps put you on the right track. I had a hard time with the same thing until I found something similar to this.

Michael D. Kirkpatrick
- 488
- 4
- 16