为什么实体框架向导在chinook数据库中看不到我的外键?

时间:2011-05-31 00:45:28

标签: sql-server visual-studio-2010 entity-framework

我正在尝试使用所有表为chinook数据库创建一个简单的Entity模型,而Vs2010没有创建任何关系或导航属性。它们肯定存在,它们出现在SSMS的数据库图中。

我有另一台机器(也是vs2010 sp1和sql express 2008 r2)没有这个问题,但我不知道那里有什么不同。

以下是创建的模型的样子: Chinook Model Without Associations

2 个答案:

答案 0 :(得分:4)

创建数据库时,请跳过以下行。我相信他们会混淆EF:

CREATE UNIQUE INDEX [IPK_Album] ON [dbo].[Album]([AlbumId]);
GO
CREATE UNIQUE INDEX [IPK_Artist] ON [dbo].[Artist]([ArtistId]);
GO
CREATE UNIQUE INDEX [IPK_Customer] ON [dbo].[Customer]([CustomerId]);
GO
CREATE UNIQUE INDEX [IPK_Employee] ON [dbo].[Employee]([EmployeeId]);
GO
CREATE UNIQUE INDEX [IPK_Genre] ON [dbo].[Genre]([GenreId]);
GO
CREATE UNIQUE INDEX [IPK_Invoice] ON [dbo].[Invoice]([InvoiceId]);
GO
CREATE UNIQUE INDEX [IPK_InvoiceLine] ON [dbo].[InvoiceLine]([InvoiceLineId]);
GO
CREATE UNIQUE INDEX [IPK_MediaType] ON [dbo].[MediaType]([MediaTypeId]);
GO
CREATE UNIQUE INDEX [IPK_Playlist] ON [dbo].[Playlist]([PlaylistId]);
GO
CREATE UNIQUE INDEX [IPK_PlaylistTrack] ON [dbo].[PlaylistTrack]([PlaylistId], [TrackId]);
GO
CREATE UNIQUE INDEX [IPK_Track] ON [dbo].[Track]([TrackId]);
GO

答案 1 :(得分:1)

确保在项目的编译选项中定位.NET Framework 4.0。

另外,请确保选中了在模型中包含关系的选项。

enter image description here

More Details Here

And some Background Here

相关问题