使用NHibernate在中间表上使用其他数据 [英] Using Additional Data on Intermediate Table with NHibernate

查看:59
本文介绍了使用NHibernate在中间表上使用其他数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个项目,该项目用于将有关产品的信息输入到文档中.一个部分的表单可以根据特定产品的需要填写多次.然后可以使用此表格上的信息在多个相关文档上共享.典型的多对多情况.区别在于,在中间表上,我要存储该特定文档的表单条目的特定信息.

I'm working on a project that is used to input information about a product into a document. One section has a form that can be filled out as many times as needed for a particular product. The information on this form is then available to be shared on multiple related documents. A typical many-to-many situation. The difference is, on the intermediate table, I want to store specific information for that form entry for that specific document.

以下是一些表定义来说明这一点:

Here are some table definitions to illustrate the point:

Document(
  Id int identity(1,1),
  Name nvarchar(256)
)

Form(
  Id int identity(1,1),
  FormData nvarchar(max)
)

DocumentForms(
  DocumentId int,
  FormId int,
  DocumentFormNumber varchar(64)
)

以及一些课程:

public class Document{
  public int Id { get; protected set; }
  protected IList<Form> Forms { get; set; }
}

public class Form {
  public int Id { get; protected set; }
  public string DocumentFormNumber { get; set; }
  public string FormData { get; set; }
}

是否存在一种创建映射的方法,该映射支持在读取表单时作为与Document的多对多关系的一部分来读取附加数据?加载具有多对多关系的数据时,是否需要使用存储过程?我仍然需要能够在不将Form对象作为文档一部分的情况下加载它们,但是一旦将它们添加到文档中,我就需要它们具有基于一些简单规则生成的数字.但是这个数字显然是特定于文档的.因此,尽管下一个文档可能使用相同的表单数据,但它需要一个新的数字.

Is there a way to create a mapping that supports reading the additional data when reading forms as part of the many to many relationship with Document? Do I need to use a stored procedure when loading data with the many to many relationship? I still need to be able to load the Form objects without them being a part of a document, but once they are added to the document, I need them to have a number that is generated based on some simple rules. But that number is obviously document specific. So while the next document might use the same Form data, it needs a new number.

关于如何实现此目标的任何建议?

Any suggestions on how this can be achieved?

推荐答案

我在Billy McCafferty的博客文章

I found my answer in a blog post by Billy McCafferty here.

这篇关于使用NHibernate在中间表上使用其他数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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