views:

191

answers:

1

Hi there,

i have these 2 classes:

    public class Category
        {
            IDictionary<string, CategoryResorce> _resources;
        }

    public class CategoryResource
        {
            public virtual string Name { get; set; }
            public virtual string Description { get; set; }
        }

and this is xml mapping

<class name="Category" table="Categories">
  <id name="ID">
    <generator class="identity"/>
  </id>
  <map name="Resources" table="CategoriesResources" lazy="false">

      <key column="EntityID" />
      <index column="LangCode" type="string"/>

      <composite-element class="Aca3.Models.Resources.CategoryResource">
        <property name="Name" column="Name" />
        <property name="Description" column="Description"/>
      </composite-element>
  </map>
</class>

and i'd like to write it with Fluent. I found something similar and i was trying with this code:

  HasMany(x => x.Resources)
                .AsMap<string>("LangCode")
                .AsIndexedCollection<string>("LangCode", c => c.GetIndexMapping())
                .Cascade.All()
                .KeyColumn("EntityID");

but i dont know how to map the CategoryResource entity as a composite element inside the Category element.

Any advice ?

thanks

A: 

I think the mapping you're looking for is something like this:

HasMany<CategoryResource>(x => x._resources)
.AsMap<string>("LangCode")
.KeyColumn("EntityID")
.Table("CategoryResources")
.Component(x =>
    {
        x.Map(c => c.Name);
        x.Map(c => c.Description);
    })
.Cascade.All();
Chris Stavropoulos
Thanks very much ! it works !
Alessandro Di Lello