Why ef6 don't create multiple column indexes which contain foreign key column?


public class UrbanRenewalPoint
    public int Id { get; set; }
    public int UrbanRenewalId { get; set; }
    public virtual UrbanRenewal UrbanRenewal { get; set; }
    public int Order { get; set; }
    public double Latitude { get; set; }
    public double Longitude { get; set; }


public class UrbanRenewalPointConfiguration : EntityTypeConfiguration<UrbanRenewalPoint>
    public UrbanRenewalPointConfiguration()
        HasKey(p => p.Id);
        HasRequired(p => p.UrbanRenewal).WithMany(p => p.UrbanRenewalPoints).HasForeignKey(p => p.UrbanRenewalId);
        Property(p => p.UrbanRenewalId).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("PointOrder", 1) { IsUnique = true }));
        Property(p => p.Order).HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("PointOrder", 2) { IsUnique = true })).IsRequired();
        Property(p => p.Latitude).IsRequired();
        Property(p => p.Longitude).IsRequired();


            c => new
                    Id = c.Int(nullable: false, identity: true),
                    UrbanRenewalId = c.Int(nullable: false),
                    Order = c.Int(nullable: false),
                    Latitude = c.Double(nullable: false),
                    Longitude = c.Double(nullable: false),
            .PrimaryKey(t => t.Id)
            .ForeignKey("dbo.UrbanRenewal", t => t.UrbanRenewalId)
            .Index(t => t.UrbanRenewalId);

So i don't understand why migration doesn't have any code for my PointOrder index? Is there any other way for succeed this with fluent api?

PS: I can't use UrbanRenewal property when i set configuration because ef giving an error(T can not be nullable) because of that i'm using UrbanRenewalId. For now i don't like it but i added my index manually to auto-generated migration file like that;

.Index(t => new { t.UrbanRenewalId, t.Order }, unique: true, name: "PointOrder")


Regardless of the type of index being created, you need to pass an ARRAY of columns into the Index Expression.


CreateTable("dbo.SomeTable", c => new
   MyKey = c.Long(nullable: false, identity: true),
   Key = c.String(nullable: false, maxLength: 100),
   Value = c.String(nullable: false, storeType: "xml")
.PrimaryKey(t => t.MyKey, name: "PK_dbo_SomeTable");
.Index(t => new { t.Key, t.Value }, unique: false, name: "IX_dbo_SomeTable");

Remember though, this simply creates the Index in your database. You still need to add the ATTRIBUTE to your models for EF's own evil purposes ;-).


public partial class SomeTable
    public long MyKey { get; set; }

    [Index("IX_dbo_SomeTable", IsUnique = true, Order = 1)]
    public string Key { get; set; }

    [Column(TypeName = "xml")]
    [Index("IX_dbo_SomeTable", IsUnique = true, Order = 2)]
    public string Value { get; set; }

Need Your Help

Fixing migration error

ruby-on-rails ruby database migration

I tried to create a migration to add roles to my user tables but i accidentally typed AddRolesToUsers instead of AddRoleToUser. So i tried creating a new migration with the correct AddRoleToUsers but

PostgreSQL encrypted backups

security backup postgresql encryption

Is it possible to ensure that dumps taken from a PostgreSQL db are always encrypted?