none
Ef4.1 code first fluent mapping bug: mapping inherited property does not work (throws invalidoperationexception instead) RRS feed

  • Question

  • Did anyone ever tried mapping an inherited property? Because I would be glad to hear that just works and that I am making a mistake somewhere, as I am getting the following error:

    "The property 'UserName' is not a declared property on type 'Advertiser'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property. "

    My model looks like this:

    abstract class Entity { public int Id {get; set; }} 
    abstract class User : Entity { public string UserName {get; set;} } 
    sealed class Advertiser : User { } 
    

    My AdvertisementConfiguration class looks like this:

    class AdvertiserConfiguration : EntityTypeConfiguration<Advertiser> 
    { 
       public AdvertiserConfiguration() 
       { 
          // the following line indirectly causes an InvalidOperationException: 
          Property( x => x.UserName ).HasMaxLength(50); 
       } 
    } 
    

    If I change the Advertiser class so that it does not inherit from User (and pull the UserName property down) then everything works just fine.

    Thursday, November 17, 2011 4:19 PM

Answers