Click here to Skip to main content
15,904,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Problem

I need to modify class Department to make Department ID identity then make affect by migrations to database sql server 2005 .

What I Try

I changed [DatabaseGenerated(DatabaseGeneratedOption.None)] from None to identity .

then from console write enable-migrations but it give me message

Migrations have already been enabled in project 'University Data'. To overwrite

the existing migrations configuration, use the -Force parameter.I also using

-Force but no any result or changed happened .

my class Department

C#
[Table("Department")]
public partial class Department      { 
public Department()   
{    
}   
[DatabaseGenerated(DatabaseGeneratedOption.None)] 
[Key] 
public int DepartmentID { get; set; } 
public string DepartmentName { get; set; }  

  } 
 }


I have class department inside container Containerclass as following :

C#
public partial class ContainerClass : DbContext     
 { 
public ContainerClass() : base("name=mycon")      
 {   
 }   
public virtual DbSet<department> Departments { get; set; } 
 }


Table department already created in database.

update

i write also in console

1- update-database but also nothing changed


2- add-migration Department but also nothing changed column DepartmentID not changed to identity



3- i add migration then write in up() and down()
C#
AlterColumn("dbo.Department", "DepartmentID", c => c.Int(nullable: false, identity: true));
but it not change column to identity


What I have tried:

SQL
how to change department id primary key to identity and do migration to database
Posted
Updated 9-Nov-16 23:45pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900