erik0502
12/13/2023, 1:12 PMC#
protected override void Migrate()
{
Logger.LogDebug("Running migration {MigrationStep}", "AddCarTable");
if (TableExists("Cars") == false)
{
Create.Table<CarStatusSchema>().Do();
Create.Table<CarSchema>().Do();
}
else
{
Logger.LogDebug("The database table {DbTable} already exists, skipping", "Cars");
}
}
[TableName("Cars")]
[PrimaryKey("Id", AutoIncrement = true)]
[ExplicitColumns]
public class CarSchema
{
[PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)]
[Column("Id")]
public int Id { get; set; }
[Column("Model")]
public required string Model { get; set; }
[Column("CarStatusId")]
public required int CarStatusId { get; set; }
}
[TableName("CarStatus")]
[PrimaryKey("Id", AutoIncrement = true)]
public class CarStatusSchema
{
[PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)]
[Column("Id")]
public int Id { get; set; }
[Column("Status")]
public string Status { get; set; }
}
I've also tried to add this reference (code below) but it also didn't work. (I can try to recreate the error if it helps)
C#
[References(typeof(CarStatusSchema))]
[Column("Status")]
public CarStatusSchema StatusReference { get; set; }
erik0502
12/13/2023, 1:47 PMC#
[ForeignKey(typeof(CarStatusSchema), Name = "FK_Car_CarStatus", Column = "CarStatusId")]
I will let you people know if it works