I am using the fluent api for the first time . I am able to establish relationshionship using one to many and many to many relationship.
But I have a clarification using one-to-one relationship.
I have two tables tableA and tableB wherein tableA has two fields
public class tableA
{
public int tAId {get;set;}
public string desc {get;set;}
public tableB tableB {get;set;}
}
And tableB has following fields:
public class tableB
{
public int tBId {get;set;}
public int refKeyfromTableA{get;set;}
public string somedesc{get;set;}
public tableA tableA {get;set;}
}
I am defining the constraints in a separate class like :
public class tableAConfig:BaseEntity<tableA>
{
public tableAConfig()
{
HasKey(p=>p.tAId);
Property(p=>p.tAId).IsRequired();
//This line has syntatical error
HasForeignKey(p=>p.tAId);
}
}
How to define the foreign key relationship in the above class in code first approach?