在 NHibernate 的中间表上使用附加数据 [英] Using Additional Data on Intermediate Table with 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; }
}
在阅读表单时,有没有办法创建支持读取附加数据的映射,作为与文档的多对多关系的一部分?加载具有多对多关系的数据时是否需要使用存储过程?我仍然需要能够加载 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屋!