**I solved this by adding in the ForeignKey("Route") data annotation like this:**

```
[ForeignKey("Route")]
public Guid rnh_rtefk { get; set; }

```

this is my first attempt at using EF.

I have created a model using Code First from database in my MVC app using EF 6.0.0.0

In my database I have a table of Routes and a table of RunSheetHeader. A route can have many RunSheetHeader and a RunSheetHeader can have one Route. The Routes primary key is Routes.rte\_pk and this maps to the foreign key: RunSheetHeader.rnh\_rtefk.

The code generated is this:

```
public partial class Route
{
    public Route()
    {
        RunSheetHeaders = new HashSet<RunSheetHeader>();
    }

    [Key]
    public Guid rte_pk { get; set; }

    [Required]
    [StringLength(50)]
    public string rte_name { get; set; }

    public virtual ICollection<RunSheetHeader> RunSheetHeaders { get; set; }
}

[Table("RunSheetHeader")]
public partial class RunSheetHeader
{
    public RunSheetHeader()
    {
        RunSheetDetails = new HashSet<RunSheetDetail>();
    }

    [Key]
    public Guid rnh_pk { get; set; }

    [Column(TypeName = "date")]
    public DateTime rnh_date { get; set; }

    public Guid rnh_rtefk { get; set; }

    public virtual Route Route { get; set; }

    public virtual ICollection<RunSheetDetail> RunSheetDetails { get; set; }
}

```

This is from the Context class:

```
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<Route>()
        .HasMany(e => e.RunSheetHeaders)
        .WithRequired(e => e.Route)
        .HasForeignKey(e => e.rnh_rtefk)
        .WillCascadeOnDelete(false);

    modelBuilder.Entity<RunSheetHeader>()
        .HasMany(e => e.RunSheetDetails)
        .WithRequired(e => e.RunSheetHeader)
        .HasForeignKey(e => e.rnd_rnhfk)
        .WillCascadeOnDelete(false);
}

```

The error I get is:

"Invalid column name 'Route\_rte\_pk'."

and the SQL shows up in SQL Profiler as:

```
SELECT 
    1 AS [C1], 
    [Extent1].[rnh_pk] AS [rnh_pk], 
    [Extent1].[rnh_date] AS [rnh_date], 
    [Extent1].[rnh_rtefk] AS [rnh_rtefk], 
    [Extent1].[Route_rte_pk] AS [Route_rte_pk]
    FROM [dbo].[RunSheetHeader] AS [Extent1]

```

From reading the other answers here regarding similar problems it seems to be a problem with mapping the correct foreign keys, but it looks to me like that has been done correctly. Can anyone spot what I am missing?

Thanks for any help