none
TPH - Discriminator using typeof RRS feed

  • Question

  • I have a base class with 2 descendants. I want to use TPH to create the 2 descendents. The discriminator is an object with 2 types. How do I use the Fluent API to do a test on Type and not value.

    For instance:

    class abstract class BaseType();
    class TypeA():BaseType;
    class TypeB():BaseType;
    
    class abstract BaseClass()
    {
      public BaseType DescriptionType
      {
        get;
        set;
      }
    
    }
    class DescendantClassA:BaseClass;
    class DescendantClassB:BaseClass;

    If BaseClass.BaseType is of TypeA, then BaseClass is DescendantClassA. If BaseClass.BaseType is of TypeB, then the instance is DescendantClassB.

    I've tried a couple variations of:

    Map<DescendantClassA>( m => m.Requires("DescriptionType").HasValue(typeOf(TypeA)));

    However, this doesn't compile. Any suggestions
    Friday, September 21, 2012 11:27 PM

Answers

  • Thinking about this more, it probably isn't possible. The mapping works directly with the database which doesn't know anything about types and OO.

    Please let me know if this is correct.

    Saturday, September 22, 2012 1:43 AM
  • Hi Chris Cornacchia,

    Welcome to MSDN Forum.

    Discriminator will be a column of the database table, it couldn't be a complex type. : )

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, September 24, 2012 2:47 AM
    Moderator

All replies

  • Thinking about this more, it probably isn't possible. The mapping works directly with the database which doesn't know anything about types and OO.

    Please let me know if this is correct.

    Saturday, September 22, 2012 1:43 AM
  • Hi Chris Cornacchia,

    Welcome to MSDN Forum.

    Discriminator will be a column of the database table, it couldn't be a complex type. : )

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, September 24, 2012 2:47 AM
    Moderator