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 renam
-
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
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 -
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
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
-
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
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.