0

I have this POCO class :

public class MyClass
{
    public int MyKey { get; set; }
    public string Name { get; set; }
    public bool DiscriminatorField { get; set; }
    public string AnotherInfo { get; set; }
}

My database model is as such :

  • Main
    • ID int
    • Name varchar
    • DiscriminatorField bit
  • Specific1
    • ID int
    • AnotherField varchar
  • Specific2
    • ID int
    • AnotherField varchar

The question: Using fluent API (and most likely EntityTypeConfiguration), how can I create this conditional mapping where AnotherField of my entity gets filled by Specific1 if the discriminator is true, and by Specific2 if the discriminator is false?

Note: I do not want to create two different POCOs. I'm looking for something like this, but conditional.

Edit: Added the discriminator field to the POCO entity.

Community
  • 1
  • 1
Tipx
  • 7,367
  • 4
  • 37
  • 59
  • In order to condition to be checked, you have to get the value of discriminator from the database. At that point, entity framework will already expect that you have provided it with entity model definition - which you can't since you want conditional mapping. I don't see how you can manage to do that but I might be mistaken. – Admir Tuzović Mar 21 '13 at 19:31
  • Ok, I'll edit my post and add the discriminator field to my entity. Does it make it possible? – Tipx Mar 21 '13 at 20:59

0 Answers0