private void IndexColumnAdded(object sender, Microsoft.VisualStudio.Modeling.ElementAddedEventArgs e)
{
var ic = e.ModelElement as IndexColumn;
if (ic.Index == null) return;
if (ic.Index.Entity == null) return;
if (ic.Index.Entity.nHydrateModel == null) return;
if (!ic.IsInternal && !ic.Index.Entity.nHydrateModel.IsLoading && !this.Store.InUndo)
{
if (!ic.Index.Entity.nHydrateModel.IsLoading)
{
if (ic.Index.IndexType != IndexTypeConstants.User)
throw new Exception("This is a managed index and cannot be modified.");
}
}
if (!ic.Index.Entity.nHydrateModel.IsLoading)
{
if (ic.SortOrder == 0)
{
using (var transaction = this.Store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString()))
{
var max = 0;
if (ic.Index.IndexColumns.Count > 0)
max = ic.Index.IndexColumns.Max(x => x.SortOrder);
ic.SortOrder = max + 1;
transaction.Commit();
}
}
}
}