0

i have a table

table Foo
(
    id,
    FooType,
    FooTypeName,
)

FooType is an enum with fixed values hence i want to map it to

public virtual FooType FooType { get; set; }

How can i serialize the property in both columns but use only one to read and query?

Which mapping (xml, Mapping by Code, FluentMapping) doesn't matter

Firo
  • 30,626
  • 4
  • 55
  • 94

1 Answers1

1

You could create FooTypeName as a string property projecting the value of FooType, and map it as readonly.


Alternatively, if you don't need FooTypeName at all, just ignore it in your model and keep it updated with a trigger.


Or, if you feel like coding a lot, create a user type that maps FooType to the two columns.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
  • wouldn't that polluting my domain class? I have a fairly awkward legacy database and i want to keep my domainmodel as clean as possible so if the apps still using the old schema run out i can use automapping to quickly generate a nice one. I do not want to carry over broken design. – Firo Jul 19 '12 at 14:26
  • Alright, there are two alternatives... I prefer the second option, just because it's easier. – Diego Mijelshon Jul 19 '12 at 15:23
  • hmm, i already have a lot IUsertypes and even implemented a base class. I think i go with this option. thx – Firo Jul 19 '12 at 19:26