1
我們試圖使用數據庫第一個實體框架來設置新的數據庫和應用程序。實體框架沒有進行關聯和顯示聯結表
除了這一堆表格以外,一切都很好。 實體框架未建立關聯,而是在3個實例中的2個實例中顯示交匯表。
在圖片中,ProfileIntegrationToolkit和ProfileProviderPrimary應該消失,而應該是關聯。
這裏的重現表
/****** Object: Table [dbo].[AuthorizedType] Script Date: 25/02/2016 3:04:42 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AuthorizedType](
[Id] [int] IDENTITY(1,1) NOT NULL,
[NameEng] [nvarchar](250) NOT NULL,
[NameFra] [nvarchar](250) NOT NULL,
[DescriptionEng] [nvarchar](max) NULL,
[DescriptionFra] [nvarchar](max) NULL,
CONSTRAINT [PK_AuthorizedToOperateTypes] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[IntegrationToolkit] Script Date: 25/02/2016 3:04:42 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IntegrationToolkit](
[Id] [int] IDENTITY(1,1) NOT NULL,
[NameEng] [nvarchar](250) NOT NULL,
[NameFra] [nvarchar](250) NOT NULL,
[DescriptionEng] [nvarchar](max) NULL,
[DescriptionFra] [nvarchar](max) NULL,
CONSTRAINT [PK_IntegrationToolkits] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[Profile] Script Date: 25/02/2016 3:04:42 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Profile](
[Id] [int] IDENTITY(1,1) NOT NULL,
[AuthorizedToOperateTypeId] [int] NOT NULL,
[AuthorizationDate] [datetime2](7) NOT NULL,
[ProviderPrimaryId] [int] NOT NULL,
[ProviderSecondaryId] [int] NOT NULL,
[IntegrationToolkitId] [int] NOT NULL,
CONSTRAINT [PK_CyberSecurityProfile] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[ProfileIntegrationToolKit] Script Date: 25/02/2016 3:04:42 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ProfileIntegrationToolKit](
[ProfileId] [int] NOT NULL,
[IntegrationToolkitId] [int] NOT NULL,
CONSTRAINT [PK_CyberSecurityProfileIntegrationToolKitOther] PRIMARY KEY CLUSTERED
(
[ProfileId] ASC,
[IntegrationToolkitId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[ProfileProviderPrimary] Script Date: 25/02/2016 3:04:42 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ProfileProviderPrimary](
[ProfileId] [int] NOT NULL,
[ProviderId] [int] NOT NULL,
CONSTRAINT [PK_CyberSecurityProfileCredentialProviderPrimary] PRIMARY KEY CLUSTERED
(
[ProfileId] ASC,
[ProviderId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[ProfileProviderSecondary] Script Date: 25/02/2016 3:04:42 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ProfileProviderSecondary](
[ProfileId] [int] NOT NULL,
[ProviderId] [int] NOT NULL,
CONSTRAINT [PK_CyberSecurityProfileCredentialProviderSecondary] PRIMARY KEY CLUSTERED
(
[ProfileId] ASC,
[ProviderId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Provider] Script Date: 25/02/2016 3:04:42 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Provider](
[Id] [int] IDENTITY(1,1) NOT NULL,
[NameEng] [nvarchar](250) NOT NULL,
[NameFra] [nvarchar](250) NOT NULL,
[DescriptionEng] [nvarchar](max) NULL,
[DescriptionFra] [nvarchar](max) NULL,
[ParentId] [int] NULL,
CONSTRAINT [PK_CredentialProviders] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[Profile] WITH CHECK ADD CONSTRAINT [FK_AuthorizedToOperate] FOREIGN KEY([AuthorizedToOperateTypeId])
REFERENCES [dbo].[AuthorizedType] ([Id])
GO
ALTER TABLE [dbo].[Profile] CHECK CONSTRAINT [FK_AuthorizedToOperate]
GO
ALTER TABLE [dbo].[Profile] WITH CHECK ADD CONSTRAINT [FK_ProvidersPrimary] FOREIGN KEY([ProviderPrimaryId])
REFERENCES [dbo].[Provider] ([Id])
GO
ALTER TABLE [dbo].[Profile] CHECK CONSTRAINT [FK_ProvidersPrimary]
GO
ALTER TABLE [dbo].[Profile] WITH CHECK ADD CONSTRAINT [FK_ProvidersSecondary] FOREIGN KEY([ProviderSecondaryId])
REFERENCES [dbo].[Provider] ([Id])
GO
ALTER TABLE [dbo].[Profile] CHECK CONSTRAINT [FK_ProvidersSecondary]
GO
ALTER TABLE [dbo].[Profile] WITH CHECK ADD CONSTRAINT [FK_Profile_IntegrationToolkit] FOREIGN KEY([IntegrationToolkitId])
REFERENCES [dbo].[IntegrationToolkit] ([Id])
GO
ALTER TABLE [dbo].[Profile] CHECK CONSTRAINT [FK_Profile_IntegrationToolkit]
GO
ALTER TABLE [dbo].[ProfileIntegrationToolKit] WITH CHECK ADD CONSTRAINT [FK_ProfileIntegrationToolKit_Profile] FOREIGN KEY([ProfileId])
REFERENCES [dbo].[Profile] ([Id])
GO
ALTER TABLE [dbo].[ProfileIntegrationToolKit] CHECK CONSTRAINT [FK_ProfileIntegrationToolKit_Profile]
GO
ALTER TABLE [dbo].[ProfileIntegrationToolKit] WITH CHECK ADD CONSTRAINT [FK_ProfileIntegrationToolKit_IntegrationToolkit] FOREIGN KEY([ProfileId])
REFERENCES [dbo].[IntegrationToolkit] ([Id])
GO
ALTER TABLE [dbo].[ProfileIntegrationToolKit] CHECK CONSTRAINT [FK_ProfileIntegrationToolKit_IntegrationToolkit]
GO
ALTER TABLE [dbo].[ProfileProviderPrimary] WITH CHECK ADD CONSTRAINT [FK_ProfileProviderPrimary_Provider] FOREIGN KEY([ProfileId])
REFERENCES [dbo].[Provider] ([Id])
GO
ALTER TABLE [dbo].[ProfileProviderPrimary] CHECK CONSTRAINT [FK_ProfileProviderPrimary_Provider]
GO
ALTER TABLE [dbo].[ProfileProviderPrimary] WITH CHECK ADD CONSTRAINT [FK_ProfileProviderPrimary_Profile] FOREIGN KEY([ProfileId])
REFERENCES [dbo].[Profile] ([Id])
GO
ALTER TABLE [dbo].[ProfileProviderPrimary] CHECK CONSTRAINT [FK_ProfileProviderPrimary_Profile]
GO
ALTER TABLE [dbo].[ProfileProviderSecondary] WITH CHECK ADD CONSTRAINT [FK_ProfileProviderSecondary_Provider] FOREIGN KEY([ProviderId])
REFERENCES [dbo].[Provider] ([Id])
GO
ALTER TABLE [dbo].[ProfileProviderSecondary] CHECK CONSTRAINT [FK_ProfileProviderSecondary_Provider]
GO
ALTER TABLE [dbo].[ProfileProviderSecondary] WITH CHECK ADD CONSTRAINT [FK_ProfileProviderSecondary_Profile] FOREIGN KEY([ProfileId])
REFERENCES [dbo].[Profile] ([Id])
GO
ALTER TABLE [dbo].[ProfileProviderSecondary] CHECK CONSTRAINT [FK_ProfileProviderSecondary_Profile]
GO
我是不是做錯了什麼碼? 我試過在SSMS中重新創建約束,但結果相同。
編輯1- 如果我嘗試減少我導入的表的數量。我遇到類似的問題。
謝謝。我會在早上試一試。嗯,我將不得不明白爲什麼在SSMS的圖表模式中創建外鍵關係時發生這種情況(所以這不會再發生) – Lareau
像魅力一樣工作。我想在創建我的外鍵關係時,我沒有在SSMS的圖表模式中注意。再次感謝! – Lareau