简体   繁体   English

Fluent-nHibernate使用结果

[英]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. 当我从数据库收到实体时,我无法序列化它,也无法通过Web服务发送它。 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 我有一个特殊的响应类,在响应Web服务调用时将数据包装在其中

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". “ [XmlInclude(typeof(Response))]”和“ [XmlInclude(typeof(MyTable)))”导致表“ MyTable”在“ Response”中序列化为XML。 If you reference "MyTable" as a list you will need "[XmlInclude(typeof(List))]". 如果引用“ MyTable”作为列表,则需要“ [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. 在找到类似的东西之前,我很难过同样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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