Update: I should have noted that the Id
property on NavigationPropertyClass
is not database generated. In my actual model, NavigationPropertyClass
is also part of a hierarchy scheme (using TPH) which is not shown here , and while NavigationPropertyClass
has a DerivedClass1
instance and a collection of DerivedClass2
instances, this is not necessarily the case with all classes that inherit from the base class from which NavigationPropertyClass
is derived.
A portion of my model looks something like this (other properties and constructors omitted for brevity):
//Many other classes inherit from this class
//and many of the derived classes are not composed of DerivedClass1 or DerivedClass2
public abstract SomeOtherBaseClass{
public int Id {get; set;} //not database generated, set in the constructor
}
public NavigationPropertyClass: SomeOtherBaseClass{
public DerivedClass1 Derived1 {get; set;}
public virtual ICollection<DerivedClass2> Derived2Collection {get; set;}
}
public abstract class BaseClass{
public int Id {get; set;}
//other properties shared by derived classes
}
public class DerivedClass1: BaseClass{
public NavigationPropertyClass NavigationProperty {get; set;}
//other properties pertinent to DerivedClass1
}
public class DerivedClass2: BaseClass{
public NavigationPropertyClass NavigationProperty {get; set;}
//other properties pertinent to DerivedClass2
}
DerivedClass1
has a 1-1 relationship with NavigationPropertyClass
, while DerivedClass2
has a many-1 relationship with NavigationPropertyClass
.
I'm trying to set up identifying relationships in each of the derived classes so that when the instance of NavigationPropertyClass
is deleted from the database, so too will the associated instance of DerivedClass1
and any instances of DerivedClass2
. The only way I can see to set this up is with TPT inheritance, but even so, I cannot get things working correctly. I'd post my Fluent API configuration, but I've tried so many permutations at this point that I wouldn't know which one to post.
Is there any way to do what I'm trying to do? If so, what does the Fluent API config look like?