I've met the same issue .
First:
I changed Role Name Index by the code in :
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
rolesTable.Property(x => x.Name)
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("RoleNameIndex") { IsUnique = false }));
}
when i save the roles twice like this:
db.roles.add(role);
db.savechanges();
db.roles.add(role2);//role.name == role2.name && role.companyid != role2.companyid
db.savechanges();
the code show error but it works fine this way:
db.roles.add(role);
db.roles.add(role2);//role.name == role2.name && role.companyid != role2.companyid
db.savechanges();
it is not very good so.
Last I recommend:
use unique role name with a companyid in it like this:
AnyRoleName#CompanyId//example:'Admin#1'
Hope it's helpful.