NHibernate和WCF序列化(单向) [英] NHibernate and WCF Serialization(Unidirectional)

查看:117
本文介绍了NHibernate和WCF序列化(单向)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类型对象图【类型】包含周期,如果参考禁止追踪无法被序列化。

我有一个简单。使用NHibernate作为我的持久层的类层次结构设置

I have a simple class hierarchy setup using NHibernate as my persistence layer.

例如:

public class Parent
{
    public virtual IList<Child> Children{get;set;}
}

public class Child
{
    public virtual Parent Parent{get;set;}
}

这仅仅是做一个有关孩子单亲,并通过数据库中的外键依然存在。 NHibernate的一部分,持久性工作得很好。通过暴露WCF Web服务这一关系时出现的问题。我知道这里有一个循环引用,并已阅读LINQ的几个解决方案,以SQL允许单向序列化,但是我无法找到不使用的dbml文件时的解决方案。

This is just done to relate a Child to a single parent and is persisted via foreign key in the database. The NHibernate part and persistence works just fine. The issue occurs when exposing this relationship via WCF web service. I realize there is a cyclical reference here and have read a few solutions for LINQ to SQL allowing for unidirectional serialization, however am unable to find a solution when not using a dbml file.



更新

这是另外的问题是,它是常见的做法是抽象的一组DTO的来通过Web服务公开,而不是原来的实体?这样就解决了问题,系列化的DTO类不一定需要循环引用(因为它们不是NHibernate的实体)。

An additional question would be, is it common practice to abstract a set of DTO's to expose via web service as opposed to the original entities? This would solve the serialization issue as the DTO classes would not necessarily need cyclic references(as they are not NHibernate entities).



<强>其他更新

我跨的文章,这可能是在正确的方向。我目前正在测试这一点,并会后,如果不成功(文章价值的缘故)。

I came across an article that may be in the right direction. I'm testing this out currently and will post if successful(for article worth's sake).

推荐答案

这是保护最佳实践您的域名,而不是让它跨进程边界去。我会建议DTO落实到抽象域。还有其他好处,包括可以提供一个意图揭示接口(客户不应该去思考如何使用该服务)。

It is best practice to protect your domain and not let it go across process boundaries. I would recommend a DTO implementation to abstract your domain. There are other benefits as well including that you can provide an intention revealing interface(clients shouldn't have to think about how to use the service).

这篇关于NHibernate和WCF序列化(单向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆