我在與實體框架問題關係使用Visual Studio中的實體框架創建於2010
的問題很簡單,我在SQL Server 2008數據庫時,我導入的表在Visual Studio 2010項目中創建edmx文件(使用ADO.NET實體數據模型),並非所有關係都在模型中複製,只是其中的一部分。我試着刪除重新創建模型,更新,甚至在一個完全新的項目同樣的問題變得....
例如:
這種實體被稱爲「simte_plandeestudio」
創建步驟腳本這個表是:
CREATE TABLE [dbo].[simte_PlanDeEstudio](
[Id] [uniqueidentifier] NOT NULL,
[Estudiante] [uniqueidentifier] NULL,
[Curso] [uniqueidentifier] NULL,
[Duracion] [int] NOT NULL,
[Meta] [int] NOT NULL,
[Estado] [int] NOT NULL,
[FechaFinalizacion] [datetime] NULL,
[Tutor] [uniqueidentifier] NULL,
[FechaInicio] [datetime] NOT NULL,
[MotivoRetiro] [varchar](50) NULL,
[FechaIngresoTaller] [datetime] NOT NULL,
[FechaMatricula] [datetime] NOT NULL,
[TiempoTranscurrido] [int] NOT NULL,
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
SET ANSI_PADDING OFF
GO
**ALTER TABLE [dbo].[simte_PlanDeEstudio] WITH CHECK ADD CONSTRAINT [FK_simte_PlanDeEstudio_simte_Curso] FOREIGN KEY([Curso])
REFERENCES [dbo].[simte_Curso] ([Id])
GO
ALTER TABLE [dbo].[simte_PlanDeEstudio] CHECK CONSTRAINT [FK_simte_PlanDeEstudio_simte_Curso]
GO**
**ALTER TABLE [dbo].[simte_PlanDeEstudio] WITH CHECK ADD CONSTRAINT [FK_simte_PlanDeEstudio_simte_Estudiante] FOREIGN KEY([Estudiante])
REFERENCES [dbo].[simte_Estudiante] ([Id])
GO
ALTER TABLE [dbo].[simte_PlanDeEstudio] CHECK CONSTRAINT [FK_simte_PlanDeEstudio_simte_Estudiante]
GO**
ALTER TABLE [dbo].[simte_PlanDeEstudio] WITH CHECK ADD CONSTRAINT [FK_simte_PlanDeEstudio_simte_Usuario] FOREIGN KEY([Tutor])
REFERENCES [dbo].[simte_Usuario] ([Id])
GO
ALTER TABLE [dbo].[simte_PlanDeEstudio] CHECK CONSTRAINT [FK_simte_PlanDeEstudio_simte_Usuario]
GO
ALTER TABLE [dbo].[simte_PlanDeEstudio] ADD CONSTRAINT [DF_simte_PlanDeEstudio_Id] DEFAULT (newid()) FOR [Id]
GO
前兩個約束條件(「simte_Curso」和「simte_Estudiante」)是出現在SQL Management Studio中圖,但不傳遞到模型。
最後一個(「simte_Usuario」)位於數據庫關係圖中並傳遞給模型。
的「simte_curso」實體並沒有外鍵和「simte_usuario」只有一個關係到另一個表
我希望它可能是外鍵更明確
創建腳本「simte_curso」和對於「simte_Usuario」是:
**CREATE TABLE [dbo].[simte_Curso](
[Id] [uniqueidentifier] NOT NULL,
[Nombre] [varchar](50) NOT NULL,
[Orden] [int] NOT NULL,
[UltimoCurso] [bit] NULL,
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]**
**CREATE TABLE [dbo].[simte_Usuario](
[Id] [uniqueidentifier] NOT NULL,
[UsuarioOrchard] [int] NOT NULL,
[TipoDeUsuario] [varchar](10) NOT NULL,
[Nombres] [varchar](50) NOT NULL,
[Apellidos] [varchar](50) NOT NULL,
[Documento] [varchar](50) NULL,
[TelefonoMovil] [varchar](50) NULL,
[FechaDeNacimento] [datetime] NULL,
[CorreoElectronico] [varchar](50) NULL,
[sexo] [bit] NULL,
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
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[simte_Usuario] WITH CHECK ADD CONSTRAINT [FK_simte_Usuario_Orch_Orchard_Users_UserPartRecord] FOREIGN KEY([UsuarioOrchard])
REFERENCES [dbo].[Orch_Orchard_Users_UserPartRecord] ([Id])
GO
ALTER TABLE [dbo].[simte_Usuario] CHECK CONSTRAINT [FK_simte_Usuario_Orch_Orchard_Users_UserPartRecord]
GO**
哪些關係哪裏沒有複製?你的數據模型是什麼樣的? – c0deNinja 2012-04-18 16:52:58
我同意@ c0deNinja在這裏 - 更多的信息會有幫助。 – JasCav 2012-04-18 17:19:51
你有沒有得到解決這個問題,我有完全相同的問題。 – StackTrace 2013-08-22 07:00:31