简体   繁体   English

我想使用 EF 6 Code First 方法重命名表

[英]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?我以前在第二种情况下有实体,不幸的是我删除了它,现在当我再次尝试使用相同名称创建时,EF 是否已缓存它我不知道,但 EF 无法识别它,有人可以请帮我解决这个问题,EF 是否缓存已创建的同名实体,我们如何清理它? 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?你能展示你的 DbContext 类吗? change your DbContext改变你的 DbContext

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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