2

I've been working on a MVC5 website to manage insurance policies, and am stuck on what I think is a design problem. I have a code first, TPH entity situation with the following abstract class called policy:

public abstract class Policy 
{

    public int PolicyID { get; set; }

    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
    public DateTime Inception { get; set; }

    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime Expiration { get; set; }
}

And two concrete classes as follows:

public class UmbrellaPolicy : Policy
{

        [Display(Name = "Umbrella:")]
        public bool hasUmb { get; set; }
        public virtual List<Umb> UmbCoverages { get; set; }
}

public class PackagePolicy : Policy
{
       [Display(Name = "General Liability:")]
       public bool hasGen { get; set; }
       public virtual List<Gen> GenCoverages { get; set; }

       [Display(Name = "Umbrella:")]
       public bool hasUmb { get; set; }
       public virtual List<Umb> UmbCoverages { get; set; }
}

And, finally a class which has a one to many relationship with both of the concrete classes above:

public class Umb
{
        public int UmbID { get; set; }

        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
        [Display(Name = "Coverage Effective")]
        public DateTime DateAdded { get; set; }

        [Display(Name = "Each Occurrence Limit")]
        public decimal OccurrenceLimit { get; set; }

        [Display(Name = "Each Occurrence Retention")]
        public decimal OccurrenceRetention { get; set; }

        [Display(Name = "Aggregate Limit")]
        public decimal AggregateLimit { get; set; }

        public virtual Policy Policy { get; set; }

}

The business requirement is if a customer wants umbrella coverage, they purchase either an umbrella policy if they want only umbrella coverage or a package policy if they want umbrella coverage and liability coverage (like those commercials that want you to bundle homeowners and auto policies). The class that describes how much insurance a customer has (the class Umb) is the same regardless of whether the customer purchased umbrella coverage in a stand-alone policy or a package.

When I try to create a new Umb and add the policy (whether umbrella or package) to the virtual Policy property, and then try to view a list of Umb objects from the list on the concrete policy class, none show up.

After looking in the database, it appears that when I did my db migration there are three key columns: UmbrellaPolicy_PolicyID, PackagePolicy_PolicyID, and Policy_PolicyID. It successfully adds the correct policy id to the Policy_PolicyID column, but I guess entity framework looks at the Umbrella or Package column depending on which concrete class I am working with (i.e. in a strongly typed view). I feel like I'm missing something obvious or I went down a shaky implementation path. Any suggestions or readings someone could point me to would be awesome. Thanks!

Ben
  • 1,032
  • 8
  • 18

0 Answers0