views:

1756

answers:

2

I have the following FNH mapping fragment:

HasManyToMany((c) => c.Plaintiffs)
    .LazyLoad()
    .WithTableName("invoicePlantiff")
    .WithChildKeyColumn("PersonReferenceID")
    .WithParentKeyColumn("invoiceID")
    .FetchType.Join();

Which produces the following HBM:

<bag name="Plaintiffs" access="iServe.Design.CslaNHibernate.CslaChildPropertyAccessor, iServe, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" lazy="true" table="invoicePlantiff">
  <key column="invoiceID" />
  <many-to-many column="PersonReferenceID" class="iServe.PersonReference, iServe, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" fetch="join" />
</bag>

The problem is that I am dealing with legacy data that is, let us just say 'less than ideal', and some records have invalid ids so I need to put the not-found="ignore" attribute on the many-to-many tag inside the bag. I do not see ANY way to accomplish this with FNH.

There is the .NotFound.Ignore() on the References() call, but not on the HasManyToMany Call.

Can someone tell me what I am missing? Even if it is a hack to 'inject' the attribute after it is rendered / before configuring NH is fine, i just need it to work.

Thanks in advance.

UPDATE gcores answer will not work, it adds it to the wrong tag, see my comment on his answer for more info.

A: 

I'm not sure about this but isn't there a SetAttribute?

HasManyToMany((c) => c.Plaintiffs)
.LazyLoad()
.WithTableName("invoicePlantiff")
.WithChildKeyColumn("PersonReferenceID")
.WithParentKeyColumn("invoiceID")
.FetchType.Join()
.SetAttributte("not-found", "ignore");

UPDATE:

Sorry about that, I knew there was a SetAttribute but I wasn't sure it did what you wanted.

Another option would be to mix Fluent NH and XML mappings, the Fluent NH wiki explains how to do this or could see this answer from stackoverflow.

gcores
Actually gcores that does nto work because it added the attribute to the `bag` and that is invalid. It needs to go on the `many-to-many` inside the bag.
Andrew Burns
+4  A: 

I've just committed a change that adds NotFound to the HasMany and HasManyToMany calls. Hope it helps!

James Gregory