Sema
Sema

Reputation: 58

Why the table is not inserted in Model.edmx file diagram

I'm using ASP.NET MVC with SQL Server and EF6, when I created the ADO.NET data model, all my tables in the database were inserted into the .edmx diagram except this one table (shown below). When I opened the .edmx properties, I found this (MODEL.SupervisorAOI Assassination) but not (MODEL.SupervisorAOI Entity Type).

Is there any error in my table?

CREATE TABLE [dbo].[SupervisorAOI] 
(
    [supervisorid] VARCHAR (50) NOT NULL,
    [AOIId] INT NOT NULL,
    [SUPAOI] INT NOT NULL IDENTITY,

    CONSTRAINT [FK_SupervisorAOI_AreaOfInterest] 
        FOREIGN KEY ([AOIId]) REFERENCES [dbo].[AreaOFInterest] ([AOIId]),
    CONSTRAINT [FK_SupervisorAOI_Supervisors] 
        FOREIGN KEY ([supervisorid]) REFERENCES [dbo].[Supervisors] ([supervisorId])
);

Upvotes: 0

Views: 206

Answers (2)

Stanley Okpala Nwosa
Stanley Okpala Nwosa

Reputation: 306

The problem I could see is that your primary key needs not to have 'not null' as primary keys are not nullable by default. Make it look like the following.

[SUPAOID] INT IDENTITY

It is also advisable to name your primary key as ID or append the primary key with Id. Your primary key could be SUPAOID or SupervisorAOIID.

Upvotes: 1

This table does not have a Primary Key. You may have SUPAOI column identity but this is not enough..

Working around EntityFramework need to have a Primary Key (Entity Key) on tables.The best practices each table should be PK. Change table structure and add a Primary Column then update Model..

 [SUPAOI] INT NOT NULL IDENTITY(1,1) PRIMARY KEY,

Note: if you do not use PK, you must provide table uniqueness , but it's not good idea..

Upvotes: 0

Related Questions