If the relationship is such that a given Resource
is owned by a single given Item
, this could be modeled like this (note: parts that matter included only):
public class Item
{
public virtual int Id { get; protected set; }
public virtual IList<Resource> Resources { get; protected set; }
// Constructor, Equals, GetHashCode, other things ... omitted.
}
public class Resource
{
public virtual Item Owner { get; protected set; }
public virtual int ResourceId { get; protected set; }
public virtual string Locale { get; protected set; }
public virtual string Value { get; protected set; }
// Constructor, Equals, GetHashCode, other things ... omitted.
}
And create the following class maps:
public class ItemMap : ClassMap<Item>
{
public ItemMap()
{
WithTable("items");
Id(x => x.Id); // add Id generation cfg if needed
HasMany(x => x.Resources)
.Inverse()
.Cascade.All()
}
}
public class ResourceMap : ClassMap<Resource>
{
public ResourceMap()
{
WithTable("resources")
CompositeId()
.KeyProperty(x => x.ResourceId)
.KeyProperty(x => x.Locale);
References(x => x.Owner)
}
}
{id, locale}
composite key) be referenced by different items? – Alex