0

I have this model definition and I want to cascade delete on it.

With modelBuilder.Entity(Of dbDimension)()
        .Property(Function(t) t.dbDimensionID).
            HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
        .HasKey(Function(t) t.dbDimensionID)
        .Property(Function(t) t.Name).
            HasColumnName("DimensionName")
        .ToTable("Dimension")

        modelBuilder.Entity(Of dbDimension)().
            HasRequired(Function(t) t.Model).
            WithMany(Function(t) t.mDimensions).
            HasForeignKey(Function(t) t.dbModelID_FK).
            WillCascadeOnDelete(True)


        modelBuilder.Entity(Of dbDimension)().
            HasMany(Function(t) t.Cubes).
            WithMany(Function(t) t.Dimensions).
        Map(Sub(m)
                m.ToTable("Dimension-Cube")
                m.MapLeftKey("dbDimensionID")
                m.MapRightKey("dbCubeID")
            End Sub)

 End With

at the moment when I delete model, dimensions get deleted as well but the many to many relationshipt doesn't get deleted. What can I do to fix this?

I'm using Dotconnect (SQLLite) as db driver.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
DataAnalyst1
  • 147
  • 2
  • 12

1 Answers1

0

Foreign key support is not enabled in SQLite by default. You need to enable it, for example by adding "Foreign Key Constraints=On" to your connection string:

Data Source=test_data.db;Foreign Key Constraints=On

If it is not the case, please send us a test project to support at devart*com , so that we are able to investigate the issue and find the solution for you.

Devart
  • 119,203
  • 23
  • 166
  • 186
  • Thanks for your reply. I tried that and now when I am trying to delete the parent with "Foreign Key Constraints=On", I get DirectCast(DirectCast(DirectCast(ex,System.Data.Entity.Infrastructure.DbUpdateException).InnerException,System.Data.UpdateException).InnerException,Devart.Data.SQLite.SQLiteException) "{"Abort due to constraint violation foreign key constraint failed"}" – DataAnalyst1 Feb 26 '14 at 20:23
  • Please send us a small test project with the definitions of the necessary database tables (or test database) to support at devart*com , so that we are able to investigate the issue and find the solution for you. – Devart Feb 27 '14 at 10:48