I am creating two tables: OrganizationUnitType - containing Id and Name OrganizationUnitDetails - containing more information about OrganizationUnitTable.
In .Core Project, I have create a new class called OrganizationUnitType : [Table("OrganizationUnitType")] public class OrganizationUnitType : Entity {
[Key]
public override int Id { get; set; }
public virtual string Name { get; set; }
public OrganizationUnitType() {
}
public OrganizationUnitType(string _name)
{
Name = _name;
}
}
}
And seeding the Data for the same after creating IDBSet in a new file under Tenants folder like below:
public class OrganizationUnitTypeCreator { private readonly MajesticDbContext _context; public OrganizationUnitTypeCreator() {
}
public OrganizationUnitTypeCreator(MajesticDbContext context)
{
_context = context;
}
public void Create()
{
var organizationUnitType1 = _context.OrganizationUnitTypes.FirstOrDefault(p => p.Name == "Door");
if (organizationUnitType1 == null)
{
_context.OrganizationUnitTypes.Add(
new OrganizationUnitType
{
Name = "ABC"
});
}
_context.SaveChanges();}}
I have also added a MigrationHistory file Up() methodwith the below data to create my second table: - OrganizationUnitDetails
CreateTable(
"dbo.OrganizationUnitDetail",
c => new
{
Id = c.Long(nullable: false, identity: true),
OrganizationUnitId = c.Long(),
OrganizationUnitTypeID = c.Int(),
StreetAddress1 = c.String(nullable: false, maxLength: 256),
StreetAddress2 = c.String(nullable: true, maxLength: 256),
City = c.String(nullable: false, maxLength: 256),
State = c.String(nullable: false, maxLength: 256),
PostalCode = c.String(nullable: false, maxLength: 256)
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.AbpOrganizationUnits", t => t.OrganizationUnitId, cascadeDelete: true)
.ForeignKey("dbo.OrganizationUnitType", t => t.OrganizationUnitTypeID, cascadeDelete: true);
After doing the above things - when I try to run the update command I am getting this error:
Column 'dbo.OrganizationUnitType.Id' is not the same data type as referencing column 'PermissionOrganizationUnitType.OrganizationUnitTypeId' in foreign key 'FK_dbo.PermissionOrganizationUnitType_dbo.OrganizationUnitType_OrganizationUnitTypeId'. Could not create constraint. See previous errors.
I don't quite understand because the data type I have specified in class for OrganizationUnitType is same as the foreign key specified in migration history file.
Can someone please point me in the right direction?
2 Answer(s)
-
0
Issue is resolved. Was looking in the wrong place.
-
0
thanks for your feedback ;)