实体框架 - 将字段转换为枚举

时间:2015-02-05 18:31:25

标签: c# .net entity-framework enums entity-framework-6

我有以下结构:

CREATE TABLE [dbo].[Decisions](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [DecisionName] [nvarchar](250) NOT NULL,
 CONSTRAINT [PK_Decisions] 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].[Vacancies](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [DecisionID] [int] NOT NULL,
    .....
 CONSTRAINT [PK_Vacancies] 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]

ALTER TABLE [dbo].[Vacancies]  WITH CHECK ADD  CONSTRAINT [FK_Vacancies_Decisions] FOREIGN KEY([DecisionID])
REFERENCES [dbo].[Decisions] ([ID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[Vacancies] CHECK CONSTRAINT [FK_Vacancies_Decisions]
GO

所以,正如您所看到的,决策和职位空缺相互关联为一对多。 好。然后我在我的.NET应用程序中创建一个ADO.NET实体数据模型,然后尝试将Decision for ID转换为枚举。已完成。然后我尝试编译我的应用程序并得到以下错误:

  

错误2错误112:从属角色中所有属性的类型   引用约束必须与相应的约束相同   主体角色中的属性类型。财产的类型   ' DecisionID'实体' VTSModel.Vacancy'与类型不匹配   财产' ID'实体' VTSModel.Decision'在参考   约束' FK_Vacancies_Decisions'。

为什么会这样?我在决策表中有4条记录(ID等于1,2,3,4),用这样的ID创建了4个枚举值,基础类型是Int32,表空位完全是空的(空置实体的DecisionID也有Int32)< / p>

我使用Visual Studio 2013 + MVC 5 + Entity Framework 6.1.2 + MS SQL 2014

0 个答案:

没有答案