Willy
Willy

Reputation: 10650

Cannot add junction tables (as a result of many to many relationship) to entity data model designer (edmx)

I have a database model in entity framework. The edmx has some tables and now I am trying to add two new ones (they are junction tables). I have seen that someone added these 2 tables in the past but for some reason these tables were not being shown in the diagram. They are not listed in the list of Entity Types (under Diagram node), but I do see it in the Entity Store.

I have done below things:

  1. Edit edmx file and delete all the entries regarding to these 2 tables. Then from edmx designer I have added these 2 junction tables through 'update model from database..." option. These 2 junction tables are shown there and they are available to be added. Tables continue without being shown in diagram.
  2. Select and delete all the tables in the edmx diagram and then add all them again to the edmx. Again, tables continue without being shown in diagram.

These 2 tables have their primary key and also foreign keys pointing to other tables already shown in the edmx diagram. Also these 2 tables are junction tables as a result of a many to many relationship between 2 tables.

Also I have restarted visual studio, clean all the solution and rebuild again without success.

Any idea what can I do to add these 2 tables?

UPDATE #1: Also classes are not being created in the disk.

SQL Server definition for one of the tables is as below (the another table is similar):

CREATE TABLE [dbo].[DeptPerson](
    [deptId] [int] NOT NULL,
    [personId] [varchar](20) NOT NULL,
 CONSTRAINT [PK_DeptPerson] PRIMARY KEY CLUSTERED 
(
    [deptId] ASC,
    [personId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [dbo].[DeptPerson]  WITH CHECK ADD  CONSTRAINT [FK_DeptPerson_Department] FOREIGN KEY([deptId])
REFERENCES [dbo].[Department] ([deptId])
GO

ALTER TABLE [dbo].[DeptPerson] CHECK CONSTRAINT [FK_DeptPerson_Department]
GO

ALTER TABLE [dbo].[DeptPerson]  WITH CHECK ADD  CONSTRAINT [FK_DeptPerson_Person] FOREIGN KEY([personId])
REFERENCES [dbo].[Person] ([personId])
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[DeptPerson]  CHECK CONSTRAINT [FK_DeptPerson_Person]
GO

UPDATE #2: AS Gert Arnold explained, junction tables (intermediate tables) are being hidden by design in many to many relationship (my case). Also it is confirmed in this post. I didn't know that junction tables were being hidden by design...

Upvotes: 0

Views: 177

Answers (0)

Related Questions