2013-01-03 40 views
1

我使用實體框架版本5.0從數據庫構建了實體模型。以下DDL用於創建表:Microsoft Entity Framework不顯示某些表的外鍵

CREATE TABLE [dbo].[Replenishment](
    [replenishmentId] [int] IDENTITY(1,1) NOT NULL, 
    [locationID] [int] NOT NULL, 
    [inventoryItemId] [int] NOT NULL, 
PRIMARY KEY CLUSTERED 
    ([replenishmentId] 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 

ALTER TABLE [dbo].[Replenishment] 
    WITH CHECK ADD CONSTRAINT [FKReplenishm163678] 
    FOREIGN KEY([inventoryItemId]) 
    REFERENCES [dbo].[InventoryItem] ([inventoryItemId]) 
GO 

ALTER TABLE [dbo].[Replenishment] CHECK CONSTRAINT [FKReplenishm163678] 
GO 

ALTER TABLE [dbo].[Replenishment] 
    WITH CHECK ADD CONSTRAINT [FKReplenishm580804] 
    FOREIGN KEY([locationID]) 
    REFERENCES [dbo].[Location] ([locationID]) 
GO 

ALTER TABLE [dbo].[Replenishment] CHECK CONSTRAINT [FKReplenishm580804] 
GO 

當我建立一個與表補貨,位置和InventoryItem,所有三個表的模型顯示了一個實體模型,但沒有關係的事情。

有誰知道爲什麼外鍵或導航屬性不顯示?

============================================== ==============================

這是來自關聯表的DDL: 這是從其他兩個表:

CREATE TABLE [dbo].[Location](
[locationID] [int] IDENTITY(1,1) NOT NULL, 
[addressID] [int] NULL, 
[availabilityStatusID] [int] NOT NULL, 
[inLocationId] [int] NULL, 
[locationTypeID] [int] NOT NULL, 
[locationName] [varchar](40) NOT NULL, 
[locationDescription] [varchar](100) NOT NULL, 
[locationAnchorX] [int] NULL, 
[locationAnchorY] [int] NULL, 
[locationImage] [varchar](255) NULL, 
[diagramLayerId] [int] NULL, 
[locationShapeParameters] [varchar](max) NULL, 
[locationHeight] [int] NULL, 
    [locationWidth] [int] NULL, 
    [locationColor] [varchar](20) NULL, 
PRIMARY KEY CLUSTERED 
(
[locationID] 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 

SET ANSI_PADDING OFF 
GO 

ALTER TABLE [dbo].[Location] WITH CHECK ADD CONSTRAINT [FKLocation209934] FOREIGN KEY([inLocationId]) 
REFERENCES [dbo].[Location] ([locationID]) 
GO 

ALTER TABLE [dbo].[Location] CHECK CONSTRAINT [FKLocation209934] 
GO 


CREATE TABLE [dbo].[InventoryItem](
[inventoryItemId] [int] IDENTITY(1,1) NOT NULL, 
[itemTaxonomyId] [int] NOT NULL, 
[itemDescription] [varchar](100) NOT NULL, 
[itemCode] [varchar](40) NULL, 
[batchControlled] [bit] NOT NULL, 
[assemblyDefinitionID] [int] NULL, 
PRIMARY KEY CLUSTERED 
(
    [inventoryItemId] 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 

SET ANSI_PADDING OFF 
GO 
+0

我從我的工作數據庫中提取了ddl,並將其插入到一個新的數據庫中。現在實體框架找到了外鍵。我在工作數據庫中看到沒有任何缺陷。任何關於在哪裏可以找到問題的建議將不勝感激。 –

+0

'Location'和'InventoryItem'表的'locationID'和'inventoryItemId'主鍵? –

+0

您是否可以包含Location和InventoryItem的ddl以便我們可以運行repro? –

回答

0

我相信我發現了這個問題。我一直在做一些SQL Server身份驗證的工作,有些人使用Windows身份驗證。使用Windows身份驗證輸入的信息未被我的Visual Studio看到,它使用SQL Server身份驗證進行連接。

經過進一步研究,我發現情況並非如此。我仍然爲此感到困惑。

+0

我的原始答案證明是不正確的。 –

相關問題