protected override void OnDeleting()
{
if (this.Index != null)
{
if (!this.Index.Entity.nHydrateModel.IsLoading && !this.Index.Entity.IsDeleting)
{
//If this is the primary key then CANCEL
if (this.Index.IndexType == IndexTypeConstants.PrimaryKey)
throw new Exception("This is a managed index for the primary key and cannot be removed.");
//If this is the last column then remove index
if (this.Index.IndexColumns.Count == 1)
{
using (var transaction = this.Store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString()))
{
this.Index.Delete();
transaction.Commit();
}
}
}
}
base.OnDeleting();
}