More than a year later, from my first question about SO ( Filter base entity from properties of child objects ), I have a similar problem.
I have an abstract base type
public abstract class Base{ }
I have children that inherit this base type
public class Child1 : Base{ public virtual NavigationProperty NavigationProperty {get; set; } public int NavigationPropertyId {get; set} } public class Child2 : Base{ public virtual NavigationProperty NavigationProperty {get; set; } }
All child objects have a NavigationProperty property. The NavigationProperty class is similar to
public class NavigationProperty{ public virtual ICollection<Child1> Child1s {get; set;} public virtual Child2 Child2s {get; set;} }
There is a one-to-one mapping between Child2 and NavigationProperty; One-to-many relationships between Child1 and NavigationProperty. In order for this display to work, I use TPT. My first question is: can I move
public NavigationProperty NavigationProperty {get; set; }
to base class?
I have been trying this all day and have had no success. If this is not possible, I can at least access NavigationProperty from the base type. In the end, the guys have this property, I tried something like
public abstract class Base{ public abstract NavigationProperty NavigationProperty {get; set; } } .... public abstract class Child2{ public override NavigationProperty NavigationProperty {get; set; } }
But the entity infrastructure gives the following error.
Sequence contains more than one matching element
I can use something like
public abstract class Base{ public abstract NavigationProperty GetNavigationProperty(); } public abstract class Child2{ public override NavigationProperty NavigationProperty {get; set; } public override NavigationProperty GetNavigationProperty(){ return NavigationProperty; } }
But I do not want to introduce these additional methods. Are they able to do this more elegantly?
Edit:
I forgot to mention that I already tried to put the [NotMapped] attribute. I assume that the EF [NotMapped] attribute is inherited too, so the child properties are also not displayed.
I do not expect Linq-to-Entites to work. I do not want to be able to query basic objects with navigational properties. I just want to get rid of the GetNavigationProperty and SetNavigationProperty methods. Therefore, when I try to access NavigationProperty from the base class, it must be loaded into memory, thatβs all. However, after a week of effort, I do not think this is possible.