Using Additional Data on Intermediate Table with NHibernate

丶灬走出姿态 提交于 2019-12-18 09:26:48

问题


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)
)

And some classes:

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; }
}

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?


回答1:


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



来源:https://stackoverflow.com/questions/350311/using-additional-data-on-intermediate-table-with-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!