Reputation: 7105
I have a MasterUserApprovalOfficial entity with two foreign keys, MasterUserId and SoftwareSystemId. EF 7 is smart enough to figure out that these two properties are foreign keys.Here is my MasterUserApprovalOfficial class
public class MasterUserApprovalOfficial
{
public int MasterUserApprovalOfficialId { get; set; }
public int MasterUserId { get; set; }
public MasterUser MasterUser { get; set; }
public int SofwareSystemId { get; set; }
public SoftwareSystem SoftwareSystem { get; set; }
public bool Active { get; set; }
public DateTime CreateDate { get; set; }
public MasterUserApprovalOfficial()
{
CreateDate = DateTime.Now;
}
}
If I look at the table that was created the MasterUserId column was created and named as expected, the SoftwareSystemId column however is created as SoftwareSystemSoftwareSystemId
(The name of the class appended to the name of the primary key)
Is there any reason for this?
Upvotes: 0
Views: 923
Reputation: 402
public int SofwareSystemId { get; set; }
read that property again. there's a t missing :)
the second answer is also right, you don't need properties for the foreign key. A member of the class is enough
Upvotes: 3
Reputation: 14488
Use the ForeignKey
and Column
attributes to fix this:
[ForeignKey("SoftwareSystem"),Column("SoftwareSystemId")]
public int SoftwareSystemId { get; set; }
By default the foreign key will be added with "Id" behind it, but because you already have a property with that name (and EF doesn't recognize it's the foreignkey apparantly) it gets changed into SoftwareSystemSoftwareSystemId
.
Upvotes: 1