开发者

Adding a new column to a may to many relationship in NHibernate

A have this mapping:

mapping.HasManyToMany(x => x.SubVersions).Pa开发者_JAVA技巧rentKeyColumn("ParentId").ChildKeyColumn("SubVersionId").Table( "VersionLinks");

This will create a table VersionLinks with 2 columns(ParentId,SubVersionId). Is it possible to have in this table another column (ex. CreateDate) that will be filled automaticly (DateTiem.Now) without creating a new entity VersionLink with fields Parent, SubVersion, Date?


You could try to create the new CreateDate column manually with a default getdate() value, but I'd just create a new entity for VersionLink and convert the many-to-many to many-to-ones


For auto updating the date property, take a look at using the IPreUpdateEventListener.

As for the mapping table, I'm pretty sure you're stuck with having to create a composite-element. I had a similar issue where I wanted to add sort and weight columns. I ended up with the following mapping:

<bag
  name="criteria"
  access="field"
  table="assessment_criterion_map"
  fetch="subselect"
  cascade="save-update">
  <key column="assessment_id"/>
  <composite-element class="WeightedCriterion">
    <parent name="assessment"/>
    <many-to-one
      class="Criterion"
      name="criterion"
      access="field"
      column="criterion_id"
      cascade="save-update"
      fetch="join"/>
    <property name="Weight"/>
    <property name="SortOrder" column="sort_order"/>
  </composite-element>
</bag>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜