简体   繁体   中英

Fluent-nHibernate using results

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM