0

I've got one table for all my dictionaries: "Id, TypeId, Value" and so for particular TypeId I've got pair: "Id + Value" which is my concrete dictionary.

How do I should map it?

At the moment I can imagine that I'll have an abstract class Dictionary, and concrete classes: InvoiceTypeDictionary, PaymentTypeDictionary etc. (I can set the subclass discriminator to TypeId and that's it). But is there another way to do it, to avoid necessary a lot of subclasses?

Roman Motyka
  • 649
  • 1
  • 6
  • 15

1 Answers1

0

I'm not sure what value is for.

// InvoiceTypeMap : ClassMap<InvoiceType>
public InvoiceTypeMap()
{
    Table("dictionaryTable");
    Where("typeid=5");
    Map(it => it.SomeProperty, "value");
}

// PaymentTypeMap : ClassMap<PaymentType>
public PaymentTypeMap()
{
    Table("dictionaryTable");
    Where("typeid=3");
    Map(it => it.SomeOtherProperty, "value");
}


void SetInvoiceTypeToEntity(Invoice invoice, int invoicetypeid)
{
    invoice.Invoicetype = session.Get<InvoiceType>(invoicetypeid);
    // or when you only need the Reference without the actual object here
    invoice.Invoicetype = session.Load<InvoiceType>(invoicetypeid);
}
Firo
  • 30,626
  • 4
  • 55
  • 94