我在使用实体框架时遇到问题
问题很简单,我在 sql server 2008 中有一个数据库。当我在 Visual Studio 2010 项目(使用 ADO.NET 实体数据模型)中导入用于创建 edmx 文件的表时,并非所有关系都在模型中复制,只是其中的一部分。我已经尝试删除重新创建模型,更新甚至在一个全新的项目中,同样的问题变成了......
例如:
这个实体被称为“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**