0

My main problem is, i want to create relationship between 2 tables.

In SQL Management studio i opened the 2 tables and created a relationship between them. Then, when i started to Generate a new model from the database in Visual Studio, everything works fine, but i can't see my new relationship. I've tried to make an association inside the Model.edmx between the two tables, it made a Foreign key inside the 'B' table (that i wanted to reach from 'A'), but after all Visual Studio is crying with an exception: InnerException "Invalid column name '' What am i doing wrong? Where should i see the relationships in Visual Studio Model Browser? Any other solutions for my problem?

G-man
  • 1
  • 1
  • see this link: https://stackoverflow.com/questions/19591513/how-to-add-foreign-key-relationship-in-entity-framework – Husni Salax Dec 19 '17 at 13:49
  • Is the foreign key assigned to the primary key of the other table? Is the column visible in the A table model diagram? The relationship should be shown as a line between the two tables. – Steve Wakeford Dec 19 '17 at 14:00
  • check this : https://msdn.microsoft.com/en-us/library/jj206878(v=vs.113).aspx – yazan Dec 19 '17 at 14:15

1 Answers1

0

There are two ways (maybe more and I don't know about it)

1: (Recommended) right click inside your model on an empty space, select Update Model from Database, and in last screen click OK, since you don't want to add any tables you don't need to select any thing, it will refresh the modeled tables

2: Right click on your table , Add New -> Association, it's like foreign key and select your entities and multiplicity

Reza
  • 18,865
  • 13
  • 88
  • 163
  • Thank you for your answer, but i have already tried these. The problem with the first option, is when i Update my model from database, it does not refresh the actual relationship that i just added before. The problem with the second option, is when i create an Association it creates the foreign key for the 'B' model, but after i build my project (and the query executes), it crashes with the exception: "Invalid Column name ". – G-man Dec 20 '17 at 14:37