After migration, update-databse -verbose throwing the below error
To change the IDENTITY property of a column, the column needs to be dropped and recreated.
[Table("MMTABS")]
public class ASAPTabsEntity : FullAuditedEntity
{
[ForeignKey("Id")]
public virtual ASAPModulesEntity ASAPModulesEntities { get; set; }
public virtual int? PARENT_MODULE_ID { get; set; }
}
[Table("MMMODL")]
public class ASAPModulesEntity : FullAuditedEntity
{
public virtual ICollection<ASAPTabsEntity> ASAPTabsEntities { get; set; }
}
here, [ForeignKey("Id")] it is not the PK of the MMTABS table, as it is PK of the MMMODL table trying to create one to many relationship with MMMODL and MMTABS
hence I have written the above
12 Answer(s)
-
0
Show code.
-
0
Why are you setting the primary key as the foreign key?
-
0
here, [ForeignKey("Id")] it is not the PK of the MMTABS table, as it is PK of the MMMODL table trying to create one to many relationship with MMMODL and MMTABS
hence I have written the above
-
0
Id
is the PK ofMMTABS
table. -
0
yes, MMTABS have a default column named Id as PK.
though Id is also the PK OF MMODL table.
hence, How do I make relationship between MMODL and MMTABS.
-
0
You don't need
ForeignKey
attribute, it will be configured by convention: https://docs.microsoft.com/en-us/ef/core/modeling/relationships#conventions -
0
Thanks , going through the doc and let you know.
-
0
You don't need ForeignKey attribute, it will be configured by convention: https://docs.microsoft.com/en-us/ef/core/modeling/relationships#conventions
In this scenario both tables MMTABS & MMODL has same coulmn named Id as PK. so, how could make a FK relationship with convention method.
[Table("MMTABS")] public class ASAPTabsEntity : FullAuditedEntity {
public virtual int Id{get;set;}
public virtual ASAPModulesEntity ASAPModulesEntities { get; set; } public virtual int Id { get; set; } }
[Table("MMMODL")] public class ASAPModulesEntity : FullAuditedEntity { public virtual int Id{get;set;}
public virtual ICollection<ASAPTabsEntity> ASAPTabsEntities { get; set; }
}
even It throws as , To change the IDENTITY property of a column, the column needs to be dropped and recreated.
-
0
Why are you defining additional
Id
properties?As I have mentioned, you don't need
ForeignKey
attribute, so just remove it from your original code and it will be configured by convention. -
0
please share sample code
-
0
[Table("MMTABS")] public class ASAPTabsEntity : FullAuditedEntity { // [ForeignKey("ASAPModulesEntitiesId")] public virtual ASAPModulesEntity ASAPModulesEntities { get; set; } public virtual int? PARENT_MODULE_ID { get; set; } } [Table("MMMODL")] public class ASAPModulesEntity : FullAuditedEntity { public virtual ICollection<ASAPTabsEntity> ASAPTabsEntities { get; set; } }
-
0
Thanks. Its working.