I have 2 models, Registration and RegistrationCode. A registration may have a single registration code and a registration code may have a single registration.
public class Registration
{
public Registration()
{
RegistrationDate = System.DateTime.Now;
}
[Key]
public int RegistrationID { get; set; }
[DataType(DataType.DateTime)]
public DateTime? RegistrationDate { get; set; }
public RegistrationCode RegistrationCode { get; set; }
}
public class RegistrationCode
{
[Key]
public string Code { get; set; }
public bool IsUsed { get; set; }
public Registration Registration { get; set; }
}
I've tried mapping the association with Fluent API like so:
modelBuilder.Entity<Registration>()
.HasOptional(t => t.RegistrationCode)
.WithOptionalPrincipal();
But the problem is when I recreate my database with update-database, my RegistrationCode table has the following fields which suggests something is not right:
Code nvarchar(50) Unchecked
IsUsed bit Unchecked
Registration_RegistrationID int Checked
Registration_RegistrationID1 int Checked
Can someone suggest how I should do this?