I have two code fist POCOs (Appointee and Case):
public class Appointee
{
public int ID { get; set; }
public string ProfileID { get; set; }
public int? CaseID { get; set; }
public string FistName { get; set; }
public string LastName { get; set; }
public DateTime Dob { get; set; }
public string Ssn { get; set; }
public string GrantNumber { get; set; }
public virtual Case Case { get; set; }
}
public class Case
{
[Key]
public int CaseID { get; set; }
public string ProfileID { get; set; }
public int PSCStatusID { get; set; }
public virtual Appointee Appointee { get; set; }
}
In our terminology Appointee is synonymous with Profile. So the [Key] of our Appointee is ProfileID.
An appointee doesn't have to have a case assigned so I have CaseID set as nullable int - int?.
From this I get the error, something like, EndPoint cannot be determined between Case and Appointee.
I think the problem is in Case. ProfileID, the foreign key to Appointee, is supposed to be the navigation property for the Virtual Appointee Property. But I don't think it understands that the navigation prop is not AppointeeID but is ProfileID instead.
So I put this in the DbContext:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Appointee>().HasKey(a => a.ProfileID);
modelBuilder.Entity<Case>().HasKey(c => c.CaseID);
modelBuilder.Entity<Case>().HasRequired(c => c.Appointee);
modelBuilder.Entity<Appointee>().HasOptional(a => a.Case);
}
Now I get: Invalid column name 'Appointee_ProfileID'.
How can I set this up correctly.