none
invalid column in entity framework assoication RRS feed

  • Question

  • I have an existing database and tried to set a model with entity framework 5.0. Just two simple tables A and B with one to one relationship. I use EF designer to do it. Add an association with "one to one" multiplicity, then the edmx always give me a new column in the association such as tableA_B_ID, which doesn't exist in the real database. Then when I run the application, i use MVC. In the view, it always give me error, "invalid column  tableA_B_ID". So how I am supposed to do it? 
    • Edited by Helen26835 Thursday, December 11, 2014 7:38 PM
    Thursday, December 11, 2014 7:37 PM

Answers

  • Hello Helen,

    >> use EF designer to do it. Add an association with "one to one" multiplicity

    I am a bit confused about this, since you mentions that you already have a database, why not pulling tables from database to designer model directly. Or you want to create a new database according to the original one by model first approach, if so, yes, it actually would automatically generate a column representing the foreign key if you do not specify one. For specifying the one to one relationship to be based on their primary keys, you could follow below steps:

    1.Create the two tables and add association between them

    2.Right click the association (the line represents the relationship), it would show a properties windows and click the Referential Constraints, selecting the primary key column:

    3.Click Ok.

    Then it would not generate an additional column.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Helen26835 Friday, December 12, 2014 4:32 PM
    Friday, December 12, 2014 2:04 AM
    Moderator

All replies

  • I have an existing database and tried to set a model with entity framework 5.0. Just two simple tables A and B with one to one relationship. I use EF designer to do it. Add an association with "one to one" multiplicity, then the edmx always give me a new column in the association such as tableA_B_ID, which doesn't exist in the real database. Then when I run the application, i use MVC. In the view, it always give me error, "invalid column  tableA_B_ID". So how I am supposed to do it? 
    • Merged by Kristin Xie Friday, December 12, 2014 9:34 AM the same issue
    Thursday, December 11, 2014 4:38 PM
  • Thursday, December 11, 2014 5:32 PM
  • Hello Helen,

    >> use EF designer to do it. Add an association with "one to one" multiplicity

    I am a bit confused about this, since you mentions that you already have a database, why not pulling tables from database to designer model directly. Or you want to create a new database according to the original one by model first approach, if so, yes, it actually would automatically generate a column representing the foreign key if you do not specify one. For specifying the one to one relationship to be based on their primary keys, you could follow below steps:

    1.Create the two tables and add association between them

    2.Right click the association (the line represents the relationship), it would show a properties windows and click the Referential Constraints, selecting the primary key column:

    3.Click Ok.

    Then it would not generate an additional column.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Helen26835 Friday, December 12, 2014 4:32 PM
    Friday, December 12, 2014 2:04 AM
    Moderator
  • I just realized that I did not put a foreign key in my real tables. Thanks anyway.
    Friday, December 12, 2014 4:32 PM