Entity Framework not showing some entities - sql-server

I am using MVC 3 with EF. I have created a entitymodel from SQL Server db and some of the tables are not showing in diagram and in code in intellisence. I have created the model again but same problem. Those tables having many to many relationship not appearing in diagram or entity list, shown in table store. At the same time few other tables with many to many relationships are visible. What is missing here? I have check PK and FK all seems correct. SQL Server also shows them in diagram but not in Visual Studio Entity model diagram.
It is something like
Department
DeptID
(other fields)
Phones
PhoneID
Phone
Has_Phone (this is many to many) and not showing up in entity model
PhoneID
DeptID
How can I get all the phones using LINQ for a departmentID?
Please help Thanks QF

I got the solution.
If the table has only two fields, the primary keys from two other tables then EF behaves like that. The solution is to create just one more column in MNM table and update the model from database. And finally the solution will be resolved itself.
If someone knows any other better solution then please share with us.

Related

Reasonable practice for existing db with 75 tables

I'm creating a new visual studio web site using MVC4/webapi that will go against a database of 75 preexisting tables (not perfect in terms of foreign keys, etc.). I'm thinking that I will create an ado.net entity data model and select all my tables. then, when my tables change I will do the "update model".
With my linq2sql projects, I always ran sqlmetal against all my tables all the time to keep things in sync and that worked fairly well.
Is my plan to have all my tables in one ado.net entity data model reasonable? what pitfalls might I run into? Is it better to have lots of ado.net entity data models? I've tried having multiple ado.net entity models in other projects and I seem to constantly be getting my connection strings doubled in my web.config.
I did do a search on SO and did not find any discussions that directly addressed my concern.
If you followed your plan, you would miss out on an opportunity to have an entity model simpler than your database model:
Your application almost certainly doesn't need all 75 tables.
You would be missing the opportunity to consider a series of 1-1 tables as a single entity
You would be missing the opportunity to use inheritance in your model
You would be missing the opportunity to keep junction tables out of your model
You would be losing one of the greatest advantages of Entity Framework over LINQ to SQL: it does not need to stay one-to-one with the database.

Entity Framework 5 missing associations

I'm trying to justify using EntityFramework and falling at the very first hurdle. I'm using the database first approach. Here is what it looks like in SQL Server 2008 R2:
As you can see, VERY simple domain. The association is a one-to-many relationship between User.Id and Blog.UserId.
However, even with this incredibly simple domain, EF fails. When I import the tables, I get this:
As you can see, there is no association. The relationship is gone and no matter how many times I delete, regenerate, it will not appear. "Include foreign key columns in the model" is checked.
However, if I create the tables based with keys based on ints instead of GUIDs, the relationships are created.
Is this a bug, a limitation or my own stupidity?
It doesn't inspire my confidence. How on earth will it perform in a real-life scenario, with a hundred tables and a thousand associations?
VS 2012
SQL Server 2008 R2
EF 5
I've resolved the issue. The problem was caused by a rogue index I did not know I had on the table.
If there is a UNIQUE index on the same field as the primary key, this will cause EF to fail to generate the PK-FK relationship at all.
Simply removing the unnecessary unique index (primary enforces unique anyway), the EF designer immediately picked up the relationship.

How to get database dependency/relationship among tables

Can anyone give me an idea about database flow diagram in my SqlServer Server Management Studio? I have a database (ERBIA) in my server; I want to know about the database relationship among different tables.
You can simply click on this:
And then select the tables for which you wish to create diagrams (graphs)
By database flow diagram I think you mean an Entity Relationship Diagram (ERD). There are a number of 3rd party tools that exist to create ERDs. ERWin, Visio, ER/Studio are some examples.
These tools can read the database schema information and create a diagram and draw relationship lines based on the Foreign Key constraints. You can edit the diagrams and depending on the tool update the database or generate a DDL script for the database changes.
SQL Server also includes a database designer, but it should be noted there is no separation from a logical model and the physical model. This means if you draw a line from one table to another indicating a relationship a FK will actually be created when you save the diagram. For some scenarios this would be a problem.

How to put Database Tables in MVC Models

I'm new in developing in MVC and I have some doubts in how to build the Models. I don't know if I must build them in terms of Database Tables or in other terms.
I have for example this 5 tables:
Domain
Category_Domains
Countries_Domains
Categories
Countries
How can i Build a Models to do actions in these Database Tables. Should I built the SQL commands to Insert, Delete and Update for each one of these Tables or I should do other thing than this?
Sorry if I not explain well.
The best advice I can give you is to look into the entity framework. Using this framework, you can create a data connection to your SQL database and the framework will create your model based on your table structure, including relationships.
Doing this will ensure your database is modelled correctly and kept in sync at all times

EER mysql workbench diagram

I'm new to CakePHP & Mysql Workbench and i just did a reverse engineer to a a open source application built with cakephp(Croogo CMS). In order to better understand the relations between tables I'll like to draw them, but using the mysql workbench the tables are getting new columns as foreign keys. I assume this isn't the right way to do it.
My questions are:
1) How to use mysql workbench in order to draw/see the relations between tables?
2) Do you know where can I find a EER mysql workbench diagram which use the cakephp convention and can help me to figure out, how this thing has to work?
The problem is that this CMS doesn't set proper relations in the database. That's why they are not retrieved from the DB.
If you know what is the relations between the tables (hopefully the Croogo CMS follow the Cake naming conventions) you can set relations between the tables by the icon "Place Relationship Using Existing Columns" (it's the last icon in the relation's toolbar). You need to select a column from a child table and then select the id column of the master table and the relation will be created.
Bear in mind that at least for me Workbench is a little bit unstable and crashes unsuspectingly - so save regularly your changes :)
You may find these graphics my Andy Dawson useful: https://github.com/AD7six/croogo/tree/mi/config/schema/graphics/

Resources