日期:2014-05-20  浏览次数:20669 次

关于Model First中的使用方法问题?
刚接触Entity Framework不久,用到Model First时,我首先建立了数据库模型,然后生成数据库脚本文件,
然后用此脚本文件在SQL SERVER 数据库中执行查询,创建实体数据库,但却发现了一个奇怪的事,就是所有表的主键都是只读属性,不能够编辑,请问这是什么原因?
附:生成的部分sql脚本文件
SET QUOTED_IDENTIFIER OFF;
GO
USE [uiy];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Ters]', 'U') IS NOT NULL
  DROP TABLE [dbo].[Ters];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Ters'
CREATE TABLE [dbo].[Ters] (
  [Id] int IDENTITY(1,1) NOT NULL,
  [Name] nvarchar(max) NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Ters'
ALTER TABLE [dbo].[Ters]
ADD CONSTRAINT [PK_Ters]
  PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------

------解决方案--------------------
主键不能更改,先删除主键,修改,再加回来。