0

I have a table structure as follows

FeedbackTable
  Id
  Name
  ...
  ...

ApprovalTable
  Id
  FeedbackId
  ...
  ...

FeedbackTable and ApprovalTable is having 1-1 relation.When i generated Model (using Database First Approach) Feedback model is having icollection of Approval Table.I need to change to 1-1 relation with navigation in the actual model class.

How can I do it? Is it possible to set 1-1 relation from the database itself before creating model?

StudentFeedback Model

 public partial class StudentFeedback
 {
    public StudentFeedback()
    {
        this.StudentProjectApprovals = new HashSet<StudentProjectApproval>();
    }

 ...
 ...
 ...
 public virtual Icollection<StudentProjectApproval> StudentProjectApprovals { get; set; }

 }
ksg
  • 3,927
  • 7
  • 51
  • 97

1 Answers1

0

The problem you have is that the schema you are providing to DB-First doesn't express a 1-1 relationship, it is a 1-N relationship, hence EF will treat as such.

How can I do it?

By making FeedbackId both a foreign key and a primary key. You will also need to remove the Id column from the ApprovalTable table

Leo
  • 14,625
  • 2
  • 37
  • 55
  • If I remove `Id` column from the ApprovalTable then what will be its primary Key?? – ksg Mar 03 '16 at 06:29
  • @ksg as I said in the answer, `FeedbackId` MUST be your primary key and your foreign key at the same time... – Leo Mar 03 '16 at 07:55