Friday, March 4, 2011

NHibernate Mapping from multiple tables

Consider the following table structure...

Appointment

ID integer Description nvarchar StatusID smallint

Status

ID smallint DisplayText nvarchar

Now, for good or for evil, we want this situation to map to a class that looks like this

class Appointment {
public int ID {g;s;} public string Description { g;s; } public string Status { g; private s; } }

I.e. we want to pull the normalised status display text straight into the entity.

From stackoverflow
  • The obvious answer is to create a Status entity and make the appointment class have a reference to that and map it in the normal way.

    Darren : If you go this way you can use the component or one-to-one mappings
  • Don't create an entity class. Use an enum and EnumStringType as shown here. This is exactly what you want I think.

0 comments:

Post a Comment