I have this problem:
have two entyties with one to one relationship, boot of them has the same Id Column name
Document_head sales_Order
+-----------------+ +------------------+
+ DocumentId + + DocumentId +
+ Person + 1-----1 + OrderDate +
+ Status + + Purchaser +
+ ... + + ... +
+ ----------------+ +------------------+
Here is the entity definition
public partial class Document_head
{
public Document_head()
{
// Other
}
[Key]
public string DocumentId {get;set;}
public int PersonId {get;set;}
public int status {get;set;}
[ForeignKey("DocumentId")]
public virtual sales_Order sales_Order { get; set; }
}
public partial class sales_order
{
public sales_order()
{
//Other
}
[Key]
public string DocumentId { get; set; }
public virtual Document_head Document_head { get; set; }
}
Here is the context
public class MyContext : DbContext
{
public DbSet Document_head Document_head{ get; set; }
public DbSet<sales_order> sales_order{ get; set; }
modelBuilder.Entity<Document_head>()
.HasOptional(p => p.sales_order).WithRequired();
modelBuilder.Entity<sales_order>()
.HasRequired(p => p.Document_head).WithOptional();
}
The problem is when run the MVC3 application.
it say:
The Column Name “Document_Head_DocumentId” is not valid.
I’m spending many time with this situation, if somebody could help me with this .. would be very appreciated.
Change the configuration as follows. You need only single configuration line and that should include both navigational fields.