I have implemented the project of EntityFramework 6 into EntityFramework Core. I have to do migrate EF6 relationship pattern into EF core . I found some references below:
but didn't get any ideas on required-optional relationship in EF-Core.
Sample1.cs:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<StudentAddress>()
.HasRequired(x => x.Student)
.WithOptional(x => x.StudentAddress);
}
public class Student
{
public int StudentId { get; set; }
public string StudentName { get; set; }
public virtual StudentAddress StudentAddress { get; set; }
}
public class StudentAddress
{
public int StudentId { get; set; }
public string State { get; set; }
public virtual Student Student { get; set; }
}
Sample2.cs:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<StudentAddress>()
.HasKey(sa => sa.StudentId);
modelBuilder.Entity<StudentAddress>()
.HasRequired(x => x.Student)
.WithOptional(x => x.StudentAddress);
}
public class Student
{
public int StudentId { get; set; }
public string StudentName { get; set; }
public virtual StudentAddress StudentAddress { get; set; }
}
public class StudentAddress
{
public int StudentId { get; set; }
public string State { get; set; }
public virtual Student Student { get; set; }
}
Kindly someone help me that how to do that in EF-Core using fluent api