I am trying to figure out how to prevent Entity Framework from creating a composite primary key on one of my tables. I have the following two entities:
public class Entry
{
public Int64 EntryID { get; set; }
public string UserName { get; set; }
public string EntrySubject { get; set; }
}
public class Revision
{
public Int64 RevisionID { get; set; }
public string RevisionDescription { get; set; }
public Int64 EntryID { get; set; }
public Entry Entry { get; set; }
}
When Entity Framework generates the database, the Revisions table gets a composite primary key made up of RevisionID and EntryID. I would like the primary key for the Revisions table to be RevisionID only. Is there a way to do that? (I am using Entity Framework 4.3 with SQL Server CE, if that makes a difference.)
You can create a Key Data Annotation in your Revision class, to explicitly define your key:
or using Fluent:
EDIT: Added test app and diagram
I created a test app, with a Key annotation and it created the following database, with a primary key on Revisions table with only RevisionID
Entirety of the app: