0

Trying to add a controller from my EF model, not sure what I'm doing wrong.

I created a model from my database, but when I try add a controller I get an error:

"Unable to retrieve metadata for "JobsApp.Category". Unable to determine the principal end of an association between the types "JobsApp.Job" and "JobsApp.Category". The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations."....

sarah
  • 5
  • 3
  • It would probably help to actually see your code. – Leniency Apr 16 '12 at 15:59
  • There isn't any code, except for the classes generated by EF in the edmx file. – sarah Apr 17 '12 at 10:10
  • Sorry, confused as to why adding a controller will conflict with EF. Are you scaffolding the controller? Most of all, it sounds like something's misconfigured in your edmx. 48klocs answer is probably right in that EF can't figure out which table, Job or Category, holds the primary key in the association. But, without any code or even pictures of the edmx, it's much harder to figure out what's wrong. Is the assocation one to one, one to many? No clue, so stuck making wild guesses. – Leniency Apr 17 '12 at 16:25
  • The problem was with my table relationships, I had duplicate foreign keys. Fixed the relationships, recreated the EF model and I am now able to create controllers with scaffolding from my models. Thanks – sarah Apr 18 '12 at 08:04

1 Answers1

0

It looks like you have some problems with your model classes - you're going to need to solve those first.

A question (and answer) about the "principal end of this association must be explicitly configured using either the relationship fluent API or data annotations" exception you're seeing is on SO.

Community
  • 1
  • 1
48klocs
  • 6,073
  • 3
  • 27
  • 34