I have a situation where an entity has a list of value objects associated
with it. Given that the objects are value objects from the domain model
point-of-view I'd rather not have the class cluttered up with properties
just to support database mapping. So, I'm using the mapping...
HasMany<ColorMapEntry>(Reveal.Property<ColorMap>("Entries"))
.AsMap("Value")
.KeyColumnNames.Add("ColorMapID")
.WithTableName("ColorMapEntry")
.Component(c =>
{
c.Map(x => x.Alpha);
c.Map(x => x.Blue);
c.Map(x => x.Green);
c.Map(x => x.Red);
})
.Cascade.AllDeleteOrphan();
}
This produces the hbml...
<map name="Entries" cascade="all-delete-orphan" table="ColorMapEntry">
<key column="ColorMapID" />
* <index type="System.Int32, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" column="Value" />*
<composite-element
class="GBS.VersiLabel.Core.Domain.Model.ColorMapEntry, GBS.VersiLabel.Core,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<property name="Alpha">
<column name="Alpha" />
</property>
<property name="Blue">
<column name="Blue" />
</property>
<property name="Green">
<column name="Green" />
</property>
<property name="Red">
<column name="Red" />
</property>
</composite-element>
</map>
This mapping is almost perfect but I'm stuck at how to effect the 'type'
attribute of the highlighted index element. The type of the column 'Value'
should be 'string' but I don't see how to set that.
The 'Entries' property referred to by the <map> element looks like this...
protected internal virtual IDictionary<string, ColorMapEntry> Entries
{
get
{
if (_entries == null)
{
_entries = new Dictionary<string, ColorMapEntry>();
}
return _entries;
}
set { _entries = value; }
}
I don't know that it will be helpful but the ColorMapEntry class looks like
this...
public class ColorMapEntry
{
private const int ColorPartMax = 255;
private const int ColorPartMin = 0;
private static bool colorPartInRange(int colorPart)
{
return colorPart >= ColorPartMin && colorPart <= ColorPartMax;
}
private static bool not(bool value)
{
return !(value);
}
protected internal ColorMapEntry()
{
}
public ColorMapEntry(int alpha, int red, int green, int blue)
{
if (not(colorPartInRange(alpha)))
throw new ArgumentException("alpha is not between 0 and 255.");
if (not(colorPartInRange(red)))
throw new ArgumentException("red is not between 0 and 255.");
if (not(colorPartInRange(green)))
throw new ArgumentException("green is not between 0 and 255.");
if (not(colorPartInRange(blue)))
throw new ArgumentException("blue is not between 0 and 255.");
this.Alpha = alpha;
this.Red = red;
this.Green = green;
this.Blue = blue;
}
public ColorMapEntry(int red, int green, int blue)
: this(255, red, green, blue)
{
}
public ColorMapEntry(Color color)
: this(color.A, color.R, color.G, color.B)
{
}
public virtual int Alpha { get; set; }
public virtual int Blue { get; set; }
public virtual int Green { get; set; }
public virtual int Red { get; set; }
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---