A: 

Hi, There is couple of tools that maps and builds class for you one of them is

mygeneration is the software http://sourceforge.net/projects/mygeneration/

In this page you find the templates that you need to run with the softwarehttp://www.mygenerationsoftware.com/TemplateLibrary/Archives/?query=nhibernate

After you have this in the mygeneration tool you only connect to your DB and it will generated for you

avnic
That helps his problem in absolutely no way. If he applies a generator it will not create the class structure he wants.
sirrocco
"Does anyone can point me how to create an nhibernate mapping file/files for doing that? I'm new to nhibernate and completely lost right now..."this tool absolute can help him but he need to change some of the mapping and the class after the code generated.
avnic
Let me add a precision : I'm lost only because of this specific mapping. The more classic mappings are not a problem for me (it's even better to right them by hand, so I learn!). Anyway, as sirrocco said, your solution will generate me the classic/simple mapping and not give me any clue on how to seperate the table into several classes.Thank you anyway for the tool, it could be usefull later!
Meigetsu
A: 

Unfortunately, you can't have a polymorphic structure in a component. But I'm acutally not sure if you need it.

The following code is straight from my head, so it certainly has errors or missing things and wouldn't compile. But it should show the direction:

public class ReportRow
{
  public int Id { get; private set; }
  public IList<IReportValue> Values { get; private set; }
}

public interface IReportValue
{
  public int Id{ get; set; }
  public object UntypedValue { get; }
}

public abstract class ReportValue<T> : IReportValue
{
  public int Id{ get; set; }
  public T Value { get; set; }
  public object UntypedValue { get { return Value; } }
}

public class ReportLongValue : ReportValue<long> {}
public class ReportStringValue : ReportValue<string> {}
public class ReportDateValue : ReportValue<DateTime>{}

Mapping:

<class ReportRow>
  <id ...>
  <bag name="Values" >
    <key column="RowNumber"/>
    <one-to-many class="IReportValue"/>
  </bag>
</class>

<class name="IReportValue" abstract="true">
  <id ...>
  <subclass name="ReportLongValue">
    <property name="Value" column="LongValue"/>
  </subclass>
  <subclass name="ReportStringValue">
    <property name="Value" column="StringValue"/>
  </subclass>
  <subclass name="ReportDateValue">
    <property name="Value" column="DateValue"/>
  </subclass>
</class>
Stefan Steinegger
Correct me if I'm wrong but that solution would lead to the creation of two different tables in ths database: ReportRow and IReportValue. That excactly what I would like to avoid (having a ReportRow table with only a rownumber seems unnecessary to me).
Meigetsu
That's correct, there are two tables. You could probably avoid it using custom sql for loading and storing. But this is not very straight forward. Where is this ReportRow actually used in? You could probably merge this with a table holding it.
Stefan Steinegger
It is used in a Report table. I don't think it would be a good idea to merge a report and it's rows. ;-)I got to the conclusion that nhibernate does not allow such structure, so I just gave up and created a two table solution similar to yours.
Meigetsu

related questions