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

8

9

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.

Plainspoken answered 25/5, 2015 at 5:1 Comment(21)
There must be a constraint active on that table and its not found while creating the model and hence, the error. You might want to check that in your SQL by checking the CREATE script of that table.Burgett
tblUser_setting using tblUser_info => user_id (primary_key ) as foreignKey. so do you mean to remove this constraint ?Plainspoken
Is tblUser_setting referenced by some other table in your database in any way ?Burgett
No, it is not referenced by any other table.Plainspoken
Try for once, removing the tblUser_info foreign key constraint from that table and check if it works.Burgett
ok, i check again and let you know.Plainspoken
i tried but its not working.Plainspoken
this time i havn't get error but not found tblUser_setting table also as usual.Plainspoken
Try this, CTRL+A all the entities in your model, delete them and update model from database again entirely.Burgett
Tried but not worked.Plainspoken
Double check if the table is present in the context.cs file and if it only not showing in your designer view.Burgett
No, this table also not present in context.cs, i don't think sql server version will make any differece, right now i am using VS2014 express (due to company requirement)Plainspoken
Right click on your designer view and then on Update model from database. After that a window will open and there click on refresh and then on tables and then finish. Check if that works.Burgett
before pressing finish i can see In Refresh tab that table is not visible, and after pressing finish, i can't see that table in designer.Plainspoken
If its possible, just delete that table from SQL server, recreate it and then try to update your model entirely again.Burgett
yes that i can try and let you know.Plainspoken
I deleted and recreated table then made foreginkey and then attached from entityFramework and this time also not worked.Plainspoken
Did it show that error it was showing previously /Burgett
Ohh yes, i have not paid attention on that, this time no error but table is missing.Plainspoken
Lol. This is getting interesting. Never experienced such stuff. See this link and follow steps : #28572625Burgett
See this also : entityframework.codeplex.com/workitem/453Burgett
P
17

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.

Plainspoken answered 25/8, 2015 at 4:41 Comment(1)
I didn't created the primary key for my tableFullblown
D
6

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.

Dictograph answered 29/3, 2016 at 19:10 Comment(0)
M
5

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

Maiden answered 12/10, 2016 at 15:42 Comment(0)
B
2

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

Bearcat answered 3/8, 2017 at 15:54 Comment(0)
L
0

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

Lentigo answered 11/1, 2019 at 11:2 Comment(1)
Why does that even happen?Syllabi
N
0

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.

Nisbet answered 29/3, 2020 at 1:49 Comment(2)
What´s a "weak entity"?Syllabi
Entities / Tables which don't have a primary key defined are considered weak entities.Nisbet
C
0

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

Courtland answered 24/6, 2020 at 13:7 Comment(0)
A
-1

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.

Antipasto answered 27/9, 2023 at 10:30 Comment(1)
Include is not related to the issue in the question. The issue is something entirely different.Pinnatisect

© 2022 - 2024 — McMap. All rights reserved.