简体   繁体   中英

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

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 rename already existing Entity and its columns, how can I do it any help please?

Can you show your DbContext class? change your DbContext

public DbSet<yourrenametable>yourrenametable{ get; set; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM