views:

26

answers:

2

I have 2 tables like this: (Please note the non-standard db schema naming)

table T_Pen
  TP_ID
  TP_PrimaryColorID
  TP_SecondaryColorID
  ...

table E_Color
  EC_ID
  EC_ColorName
  ...

And I want to create a mapping of the 2 tables to a domain object Pen using Fluent NHibernate.

class Pen
{
    PenID;
    PrimaryColorName;
    SecondaryColorName;
    ...
}

How can I do that?

A: 

class Pen {
int PenID;
Color PrimaryColor;
Color SecondaryColor;
}

class Color
{
int ColorID;
string ColorName;

}

class ColorMap
{
Id(x => x.ColorID);
Map(x => x.ColorName);
}

class PenMap
{
Id(x => x.PenID);
References(x => x.PrimaryColor).Column("TP_PrimaryColorID");
References(x => x.SecondaryColor).Column("TP_SecondaryColorID");
}

tonyjy
I don't want to reference a Color object in a Pen object, just the name of the colors, can this be done?
Weiming
yes, you can create a view which contains two varchar columns PrimaryColorName and SecondaryColorName. The limitation is that you won't be able to update or insert.
tonyjy
+1  A: 

I don't think you would be able to Insert/Update anymore if you were to only reference the Name.

You could create a view of PenColour or hide the actual reference in your pen class and only expose the Name property.