Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. I want to rename a table by using EF 6 Code First approach

I want to rename a table by using EF 6 Code First approach

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasehelpquestion
4 Posts 3 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    simpledeveloper
    wrote on last edited by
    #1

    Hi I have an Entity as below:

    public class Complaint
    {
    public Complaint()
    { }
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

        \[Index("IX\_UniqueConstraintComplaint", 1, IsUnique = true)\]
        public int? InspectionRequestId { get; set; }
        public InspectionRequest InspectionRequest { get; set; }
    
        \[Index("IX\_UniqueConstraintComplaint", 2, IsUnique = true)\]
        public int? InspectionResultId { get; set; }
        public InspectionResult InspectionResult { get; set; }
    
        \[Index("IX\_UniqueConstraintComplaint", 3, IsUnique = true)\]
        public int? CaseId { get; set; }
        public Case Case { get; set; }
    
        \[Index("IX\_UniqueConstraintComplaint", 4, IsUnique = true)\]
        public string ComplaintId { get; set; }
    }
    

    I want to rename this entity as below with couple of column names changed, can somebody please help me in this

    public class RequestResultCaseComplaint
    {
    public RequestResultCaseComplaint()
    { }

            \[Key\]
            \[DatabaseGenerated(DatabaseGeneratedOption.Identity)\]
            public int RequestResultCaseComplaintId { get; set; }        
    
            \[Index("IX\_UniqueConstraintComplaint", 1, IsUnique = true)\]
            public int? InspectionRequestId { get; set; }
            public InspectionRequest InspectionRequest { get; set; }
    
            \[Index("IX\_UniqueConstraintComplaint", 2, IsUnique = true)\]
            public int? InspectionResultId { get; set; }
            public InspectionResult InspectionResult { get; set; }
    
            \[Index("IX\_UniqueConstraintComplaint", 3, IsUnique = true)\]
            public int? CaseId { get; set; }
            public Case Case { get; set; }
    
            \[Index("IX\_UniqueConstraintComplaint", 4, IsUnique = true)\]
            \[Required\]
            \[StringLength(20)\]
            public string ComplaintId { get; set; }
        }
    

    I previously had the entity as in the 2nd case, unfortunately I removed it, and now when I am trying to create with same name again, whether EF has cached it I don't know, but EF is not recognizing it, can somebody please help me in this, does EF cache the already created Entities with same names, how can we clean it? Its not allowing me to create the same Entity again even after deleting the Entity and trying regenerate again. Or at least can I renam

    D L 2 Replies Last reply
    0
    • S simpledeveloper

      Hi I have an Entity as below:

      public class Complaint
      {
      public Complaint()
      { }
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }

          \[Index("IX\_UniqueConstraintComplaint", 1, IsUnique = true)\]
          public int? InspectionRequestId { get; set; }
          public InspectionRequest InspectionRequest { get; set; }
      
          \[Index("IX\_UniqueConstraintComplaint", 2, IsUnique = true)\]
          public int? InspectionResultId { get; set; }
          public InspectionResult InspectionResult { get; set; }
      
          \[Index("IX\_UniqueConstraintComplaint", 3, IsUnique = true)\]
          public int? CaseId { get; set; }
          public Case Case { get; set; }
      
          \[Index("IX\_UniqueConstraintComplaint", 4, IsUnique = true)\]
          public string ComplaintId { get; set; }
      }
      

      I want to rename this entity as below with couple of column names changed, can somebody please help me in this

      public class RequestResultCaseComplaint
      {
      public RequestResultCaseComplaint()
      { }

              \[Key\]
              \[DatabaseGenerated(DatabaseGeneratedOption.Identity)\]
              public int RequestResultCaseComplaintId { get; set; }        
      
              \[Index("IX\_UniqueConstraintComplaint", 1, IsUnique = true)\]
              public int? InspectionRequestId { get; set; }
              public InspectionRequest InspectionRequest { get; set; }
      
              \[Index("IX\_UniqueConstraintComplaint", 2, IsUnique = true)\]
              public int? InspectionResultId { get; set; }
              public InspectionResult InspectionResult { get; set; }
      
              \[Index("IX\_UniqueConstraintComplaint", 3, IsUnique = true)\]
              public int? CaseId { get; set; }
              public Case Case { get; set; }
      
              \[Index("IX\_UniqueConstraintComplaint", 4, IsUnique = true)\]
              \[Required\]
              \[StringLength(20)\]
              public string ComplaintId { get; set; }
          }
      

      I previously had the entity as in the 2nd case, unfortunately I removed it, and now when I am trying to create with same name again, whether EF has cached it I don't know, but EF is not recognizing it, can somebody please help me in this, does EF cache the already created Entities with same names, how can we clean it? Its not allowing me to create the same Entity again even after deleting the Entity and trying regenerate again. Or at least can I renam

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Be very careful with this and make sure you backup your test and production databases as you test the code and deploy it to production. I cannot stress this enough. c# - Entity Framework Migrations renaming tables and columns - SO[^]

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • S simpledeveloper

        Hi I have an Entity as below:

        public class Complaint
        {
        public Complaint()
        { }
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

            \[Index("IX\_UniqueConstraintComplaint", 1, IsUnique = true)\]
            public int? InspectionRequestId { get; set; }
            public InspectionRequest InspectionRequest { get; set; }
        
            \[Index("IX\_UniqueConstraintComplaint", 2, IsUnique = true)\]
            public int? InspectionResultId { get; set; }
            public InspectionResult InspectionResult { get; set; }
        
            \[Index("IX\_UniqueConstraintComplaint", 3, IsUnique = true)\]
            public int? CaseId { get; set; }
            public Case Case { get; set; }
        
            \[Index("IX\_UniqueConstraintComplaint", 4, IsUnique = true)\]
            public string ComplaintId { get; set; }
        }
        

        I want to rename this entity as below with couple of column names changed, can somebody please help me in this

        public class RequestResultCaseComplaint
        {
        public RequestResultCaseComplaint()
        { }

                \[Key\]
                \[DatabaseGenerated(DatabaseGeneratedOption.Identity)\]
                public int RequestResultCaseComplaintId { get; set; }        
        
                \[Index("IX\_UniqueConstraintComplaint", 1, IsUnique = true)\]
                public int? InspectionRequestId { get; set; }
                public InspectionRequest InspectionRequest { get; set; }
        
                \[Index("IX\_UniqueConstraintComplaint", 2, IsUnique = true)\]
                public int? InspectionResultId { get; set; }
                public InspectionResult InspectionResult { get; set; }
        
                \[Index("IX\_UniqueConstraintComplaint", 3, IsUnique = true)\]
                public int? CaseId { get; set; }
                public Case Case { get; set; }
        
                \[Index("IX\_UniqueConstraintComplaint", 4, IsUnique = true)\]
                \[Required\]
                \[StringLength(20)\]
                public string ComplaintId { get; set; }
            }
        

        I previously had the entity as in the 2nd case, unfortunately I removed it, and now when I am trying to create with same name again, whether EF has cached it I don't know, but EF is not recognizing it, can somebody please help me in this, does EF cache the already created Entities with same names, how can we clean it? Its not allowing me to create the same Entity again even after deleting the Entity and trying regenerate again. Or at least can I renam

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        If you're still in development, and using Code First, then just nuke the database / tables.

        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

        S 1 Reply Last reply
        0
        • L Lost User

          If you're still in development, and using Code First, then just nuke the database / tables.

          It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

          S Offline
          S Offline
          simpledeveloper
          wrote on last edited by
          #4

          Funny - I don't have nuke weapons :), I did achieve it, I manually wrote up and down methods and ran them against, challenging, scary but did it, thank you both for the help buddies.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups