Ashish-BeJovial
Ashish-BeJovial

Reputation: 1867

Referenced table is not coming in my model through entity framework 5.0

I am using MVC 4 and entity framework 5.0, i have a database and this database contains 6 tables named as following.

tblUser_family
tblUser_location
tblUser_info
tblUser_photo
tblUser_settings
tblUser_social

when i am creating the .edmx file then only 5 tables are coming in designer one table "tblUser_settings" is not coming, while all tables are connected through foreginKeys.

I am getting following error

Error 1 Error 6004: The table 'Community.dbo.tblUser_settings' is referenced by a relationship, but cannot be found.

Upvotes: 9

Views: 11932

Answers (8)

Sanskar7_8
Sanskar7_8

Reputation: 7

I also faced the same issue of not getting data from the reference table connected through a foreign key with the primary table. When I was trying to get the table data from DbContext class. Previously I was fetching the data using:

orders = _context.Orders.ToList();

I am not getting the reference table data. Hence, I used the "Include" functionality.

orders = _context.Orders.Include(p => p.Person).ToList();

This solution worked for me.

Upvotes: -1

Vj Shah
Vj Shah

Reputation: 1

For foreign keys, I didn't specify NOT NULL in reference tables. I updated table and update edmx file to resolve the issue.

Upvotes: 0

Peck_conyon
Peck_conyon

Reputation: 241

I had the same issue but it was that I forgot to "Write Changes". I used to work with MSSQL Server but with DB Browser for SQLite even after we run the script we still need to "Write Changes" / Ctrl + S to reflect them in the the database. Also make sure FKs are not null and in the same data type. not int but Integer etc. Also for EDMX you need to define PK in your tables. Weak entities won't be included in EDMX.

Upvotes: 0

Raj
Raj

Reputation: 31

The tables that don't have primary key won't be read by Edmx

Upvotes: 0

user3669766
user3669766

Reputation: 53

My issue was when creating the foreign keys I didn't specify NOT NULL. I made the change and the table imported just fine.

Upvotes: 2

Tiago Ávila
Tiago Ávila

Reputation: 2867

I had this problem, in my case I didn't have created the primary key to my table, so I just set it and I could update my EDMX.

Upvotes: 6

Alejandro Muñoz
Alejandro Muñoz

Reputation: 51

make sure you have "not null" in the declaration of FK

Upvotes: 5

Ashish-BeJovial
Ashish-BeJovial

Reputation: 1867

Recently i have resolved my issue, problem was i had a main table which has a primary key, and that primary key was mapped with my missing table's column in that column i set "Allow null", as i changed "Allow not null", and update my data model from Entity framework 5.0, it was visible in my solution.

Thank you for all suggestions.

Upvotes: 17

Related Questions