How can I create a foreign key with Entity Framework code-first?
I need a table post to have a column userId as a foreign key.
With the following property attribute [ForeignKey("Column Name")]. Typically you would assign a foreign key on a navigational property not the foreign key column.
Example
public class Employee { public int Employee Id { get; set; } public int ManagerId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } [ForeignKey("ManagerId")] public virtual Employee Manager { get; set; } }