Goran
Goran

Reputation: 6528

EF code first and two way relationships

this.HasRequired(t => t.Parent)
    .WithMany(t => t.Children)
    .HasForeignKey(d => d.ParentId);

Here I defined a basic 1-to-many relationship. What if I do not want to have Children property exposed at all in Model, but still want to have synchronization of values between Parent and ParentId. How would I go defining such "relationship"?

Upvotes: 0

Views: 127

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364409

You will call WithMany without any parameter:

this.HasRequired(t => t.Parent)
    .WithMany()
    .HasForeignKey(d => d.ParentId);

Upvotes: 1

Related Questions