views:

298

answers:

1

Hi,

There are 2 classes: Product and Image.

  1. The Product has only one Image.
  2. No orphan Images can exist.

This represent composition relationship in UML which means:
Assigning Product.Image a newImage results in following

  1. delete old image;
  2. insert new image;
  3. link new image to the product.

Now I need to map it to the RDBMS tables (meta-code):

Product (Id primary key, ImageId int references Image(id))  
Image(Id primary key, Content)

The question is HOW to do it using Fluent NHibernate.
PLEASE NOTE:

productMap.References(x => x.Image).Cascade.All()

is not applicable - it DOES NOT delete the orphan image.

Also NH DOES NOT support all-delete-orphan for many-to-one, on-to-one.

I probably need something like join with component...
BUT IN FLUENT NH.

UPDATE: James in FNH user groups suggested this syntax:

WithTable("other table", m => 
{
  m.Component(...);
});

But no luck with it: NotSupportedException: Obsolete
It supposed to work in v1 (upcomming) of FNH.

+1  A: 

You can map like a component ?

Mapping with Fluent : http://wiki.fluentnhibernate.org/show/StandardMappingComponents

NH doc : http://nhforge.org/doc/nh/en/index.html#mapping-declaration-component

Matthieu
Yeah. I probably need a component BUT the it should be in a separate table. So I probably need to mix *join* with *component*. Do not see how I can do this using FNH.
Dmytrii Nagirniak

related questions