PROBLEM:
I am trying to create a EF6 model using the database first approach. Simply speaking, I have 2 tables tblUser
and tblMilkMan
which have a foreign key relationship on the UserID
column. But when I create a new EDMX diagram and add the 2 tables:
- I dont see the relationship
- No navigation properties are created
Please tell me what Im doing wrong!
DB Schema:
Table Scripts:
CREATE TABLE [dbo].[tblMilkMan]
(
[RecordID] [INT] NOT NULL
IDENTITY(1, 1) ,
[UserID] [INT] NOT NULL ,
[IsMyTurn] [BIT] NOT NULL ,
[RoundRobinOrder] [INT] NOT NULL
)
ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblMilkMan] ADD CONSTRAINT [PK_tblMilkMan] PRIMARY KEY CLUSTERED ([RecordID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblMilkMan] ADD CONSTRAINT [FK__MilkMan__User__UserID] FOREIGN KEY ([UserID]) REFERENCES [dbo].[tblUser] ([UserID]) ON DELETE CASCADE
GO
CREATE TABLE [dbo].[tblUser]
(
[UserID] [INT] NOT NULL
IDENTITY(1, 1) ,
[LogonName] [VARCHAR](20) COLLATE SQL_Latin1_General_CP437_CI_AS
NOT NULL ,
[Client] [CHAR](4) COLLATE SQL_Latin1_General_CP437_CI_AS
NOT NULL ,
[Password] [VARCHAR](20) COLLATE SQL_Latin1_General_CP437_CI_AS
NOT NULL ,
[PasswordExpires] [DATETIME] NULL ,
[PasswordExpiresAfter] [INT] NOT NULL
CONSTRAINT [DF_tblUser_PasswordExpiresAfter] DEFAULT ( 9999 ) ,
[FirstName] [VARCHAR](20) COLLATE SQL_Latin1_General_CP437_CI_AS
NOT NULL ,
[LastName] [VARCHAR](20) COLLATE SQL_Latin1_General_CP437_CI_AS
NOT NULL
)
ON [PRIMARY]
WITH (
DATA_COMPRESSION = ROW)
GO
ALTER TABLE [dbo].[tblUser] ADD CONSTRAINT [PK_tblUser] PRIMARY KEY CLUSTERED ([UserID]) WITH (DATA_COMPRESSION = ROW) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_tblUser] ON [dbo].[tblUser] ([UserID]) WITH (FILLFACTOR=90, DATA_COMPRESSION = ROW) ON [PRIMARY]
GO
EDMX Designer View:
RELATED LINKS WHICH DIDNT HELP ME:
Why doesn't EF 4 generate association for FK relation to column with unique index?
EF does not generate foreign key association from foreign key in table
ENVIRONMENT:
- Visual Studio Ultimate 2012
- SQL Server 2014
- EF6
- Web API2