Hi,
I have a dictionary field in my Product class that contains prices (Money
class) per region. In other words, a dictionary containg Value Objects.
I can save the prices with correct region and amount but when I read them
from the database then I can't get the region name (Money.RegionName) to map
correctely. The Money.Amount is mapped correctely though. This is my setup.
public class ProductMap : ClassMap<Product>
{
public ProductMap()
{
Id(x => x.Id);
HasMany(x => x.Prices).Access.CamelCaseField().Cascade.All().AsMap(key
=> key.RegionName)
.Component(desc => desc.Map(x => x.Amount));
}
}
public sealed class Money : IEquatable<Money>, IComparable,
IComparable<Money>
{
private readonly string regionName;
private readonly decimal amount;
public Money()
: this(0, new RegionInfo(CultureInfo.CurrentCulture.LCID))
{
}
public Money(decimal amount, string regionName) : this(amount, new
RegionInfo(regionName))
{
}
public string RegionName
{
get { return regionName; }
}
public decimal Amount
{
get { return amount; }
}
}
Map part in hbm file:
<map access="field.camelcase" cascade="all" name="Prices" mutable="true">
<key>
<column name="Product_id" />
</key>
<index type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<column name="RegionName" />
</index>
<composite-element class="Money, Domain, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null">
<property access="field.camelcase" name="Amount" type="System.Decimal,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<column name="Amount" />
</property>
</composite-element>
</map>
If I change to this (adding map of region name in component):
HasMany(x => x.Prices).Access.CamelCaseField().Cascade.All().AsMap(key =>
key.RegionName)
.Component(desc =>
{
desc.Map(x => x.Amount).Access.CamelCaseField();
desc.Map(x => x.RegionName).Access.CamelCaseField();
});
Then I get error:
[MappingException: Repeated column in mapping for collection: Product.Prices
column: RegionName]
NHibernate.Mapping.Collection.CheckColumnDuplication(ISet`1
distinctColumns, IEnumerable`1 columns) in d:\OSS\NHibernate
2.1\nhibernate\src\NHibernate\Mapping\Collection.cs:615
I have searched for dictionary with components examples but only found for
set.
For example "7.2. Collections of dependent objects",
https://www.hibernate.org/hib_docs/nhibernate/html/components.html
Any hints?
--
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en.