Component that references a component

10 views
Skip to first unread message

Bart Reyserhove

unread,
Dec 18, 2009, 2:10:29 AM12/18/09
to fluent-n...@googlegroups.com
Given the following class structure:

public class SalesItem
{
protected virtual IList<Price> prices {get; set;}
}


public class Price
{
public virtual Money Value {get; protected internal set}
}

So we have a SalesItem item that has many prices over time. Price is a value object that has a value of type Money which is also a value object.

In my fluent mapping I can do something like this:

HasMany<Price>(Reveal.Property<SalesItem>("Prices")).Component(price =>{price.References(x => x.Value);}

but this will not work since Money is also a value object. I guess I need something like this, but that is not supported.

HasMany<Price>(Reveal.Property<SalesItem>("Prices")).Component(price =>{price.Component(money => money.Map(x => x.Amount));}

Any ideas on how this can be solved.

Thanks,

Bart

James Gregory

unread,
Dec 18, 2009, 4:12:31 AM12/18/09
to fluent-n...@googlegroups.com
I'd map your Money type as an IUserType, and then you should just be able to Map(x => x.Value).CustomType<MoneyUserType>().

--

You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.

Bart Reyserhove

unread,
Dec 20, 2009, 4:19:38 AM12/20/09
to fluent-nhibernate
The issue is that my Money class has two properties: Amount and Currency which means I cannot use a user type I guess. Am I correct that Fluent Nhibernate cannot map a component that references another component.

Paul Batum

unread,
Dec 30, 2009, 6:07:07 AM12/30/09
to fluent-nhibernate
Currently, Fluent NHibernate supports a component that has an inner
component, as long as that component is NOT a member of a collection.
The reason for this is reasonably straightforward - a collection of
components is not mapped using <component>, but rather
<composite-element> and then further inner components are mapped using
<nested-composite-element>. Its the nested element that we haven't
implemented support for yet.


On Sun, Dec 20, 2009 at 8:19 PM, Bart Reyserhove
<bart.re...@gmail.com> wrote:
> The issue is that my Money class has two properties: Amount and Currency
> which means I cannot use a user type I guess. Am I correct that Fluent
> Nhibernate cannot map a component that references another component.
>

> On Fri, Dec 18, 2009 at 10:12 AM, James Gregory <jagreg...@gmail.com>

Reply all
Reply to author
Forward
0 new messages