ahmed salah

ahmed salah

  • NA
  • 530
  • 148.9k

how to implement migration by changing to identity code firs

Nov 9 2016 6:13 AM
I have class department inside container Containerclass as following
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel.DataAnnotations;  
  4. using System.ComponentModel.DataAnnotations.Schema;  
  5. using System.Linq;  
  6. using System.Web;  
  7.   
  8. namespace UniversityData.Models  
  9. {  
  10.     [Table("Department")]  
  11.     public partial class Department  
  12.     {  
  13.         public Department()  
  14.             {  
  15.            
  16.   
  17.             }  
  18.         [DatabaseGenerated(DatabaseGeneratedOption.None)]  
  19.   
  20.         [Key]  
  21.         public int DepartmentID { getset; }  
  22.         [Required]  
  23.         [StringLength(50)]  
  24.   
  25.         public string DepartmentName { getset; }  
  26.         [Required]  
  27.         [StringLength(50)]  
  28.         public string YearName { getset; }  
  29.          
  30.   
  31.   
  32.   
  33.   
  34.   
  35.     }  
  36. }  

I need to make DepartmentID field identity then apply migrations in database
how to do that 
my container class as following
  1.  public partial class ContainerClass : DbContext  
  2.     {  
  3.         public ContainerClass() : base("name=mycon")  
  4.         {  
  5.   
  6.         }  
  7.         public virtual DbSet<Department> Departments { getset; }  
  8. }  
 Table department already created in database but only i need to modify table
to make DepartmentID IDENTITY then make migrations  

Answers (1)