与NHibernate深拷贝实体实体、NHibernate

2023-09-05 23:39:24 作者:痛恨·所謂痛也很愉快、。

我目前正在开始一个新的ASP.NET MVC项目在工作中,我们需要生成一个项目的成本估算。

I am currently starting a new ASP.NET MVC Project at work where we need to generate a project cost estimate.

我们正在使用NHibernate,ASP.NET MVC 1.0和StructureMap。

We are using NHibernate, ASP.NET MVC 1.0 and StructureMap.

客户希望能够填补有关项目的所有信息,这些信息是在不同的页面,我们需要坚持的每一个回发。

The client wants to be able to fill all the information about the project, the information is in different pages and we need to persist in between each post back.

客户端并不想一直将它保存在一个名称下,当它完成的选项,但我们要坚持在数据库中,即使他没有拯救它。因此,我们有想法创造一个草稿模式,因此用户将开始他的项目工作,将填补所有的页面,它会被保留在数据库中的草稿模式上。

The client does not want to have the option to Save it under a name when it is completed, but we want to persist it in the database even when he did not save it yet. So we had the idea to create a "Draft mode", so the user will start working on his project, will fill all the pages, and it will be persisted in the database with the "Draft mode" on.

但是,我们需要管理的草稿,我的意思是,当用户开始编辑现有的项目,我们需要创建一个副本,设置对象及其所有孩子的草稿模式,创建一个副本在我们的数据库中。我们需要改变,从孩子的所有引用。

But we need to manage the drafts, I mean, when the user will start editing an existing project, we will need to create a copy of it, set the object and all its childs to Draft mode and create a copy of it in our database. We will need to alter all the references from the childs.

所以,我试图找到深层复制对象的最佳方式,并改变所有的引用, 我想preFER到不必创建一个拷贝类的每一个实体,我将不得不复制,也可以是更通用的,如果这是可能的。

So, I am trying to find the best way to deep copy the objects and alter all the references, I would prefer to do not have to create a copying class for every entity that I will have to copy, maybe something more generic if this is possible.

请让我知道如果你需要更多的细节,或者如果有任何不明白。

Please let me know if you need more details or if something is unclear.

谢谢

查尔斯

推荐答案

我会尽量让我的域名解决这个问题,并留下NHibernate的只是挽救复制它的数据来代替。我想创建一个IDeepCopy接口定义了一个的DeepCopy()方法。然后,在这些方法中,你将创建一个新的对象,只是复制了自己的价值观和控制您希望如何正确处理子女或父母对象。

I would try to have my domain solve this issue and leave NHibernate to just saving the data instead of copying it. I would create an IDeepCopy interface that defines a DeepCopy() method. And then in each of these method you would create a new object and just copy the values yourself and control how you want to handle children or parent objects correctly.