ServiceStack Ormlite OnDelete = "CASCADE" does not work

I have the following ORM classes:

public class HotelProperties
{
    [AutoIncrement, PrimaryKey]
    public int Id { get; set; }

    [Reference]
    public List<HotelRoomInfo> HotelRoomInfo { get; set; }
}

public class HotelRoomInfo
{
    [AutoIncrement, PrimaryKey]
    public int Id { get; set; }

    [ForeignKey(typeof(HotelProperties), OnDelete = "CASCADE")]
    public int HotelPropertiesId { get; set; }
}

      

the methods db.Load()

and db.Save()

work fine, however, when I try to delete HotelProperties

, I expect HotelRoomInfo

to be deleted too. I'm not sure why it isn't working?

I've looked at ForeignKeyAttributeTests.cs and it seems to be correct. What could be wrong?

+3


source to share


1 answer


I am assuming that you are sitting in this model on top of a pre-existing database schema and that you are not asking ServiceStack to create a table. It is entirely possible that the script only creates something using syntax ON DELETE CASCADE

at FOREIGN KEY

construction time (in particular the constraint REFERENCES

). If so, and if you created the table and foreign key yourself without this option, then: it will have no effect.



These options are discussed here on MSDN ; find "Cascading Referential Integrity"

+3


source







All Articles