私は2つのクラス、UserとFollowを持っていますが、私は同じクラスに対して2つの関係を作成しましたが、私は外部キーのペアで一意性を制約する必要があります。Entity Frameworkコードファーストで仮想列にインデックスを追加する方法?
インデックスを追加しようとしましたが、動作しません。インデックスは移行コードに追加されません。ユーザーとフォローユーザーは仮想だからです。
仮想外部キーのペアに一意性を追加するにはどうすればよいですか?
ありがとうございます。
注:Azure Mobile App Serviceを使用していて、主キーフィールドが自動的に追加されます。
public class Following : EntityData
{
[Index("IX_FriendshipUniqueness", 1, IsUnique = true)]
public virtual User User { get; set; }
[Index("IX_FriendshipUniqueness", 2, IsUnique = true)]
public virtual User FollowingUser { get; set; }
[StringLength(10)]
public string Status { get; set; }
}
public class User : EntityData
{
public User()
{
this.Followings = new HashSet<Following>();
this.Followers = new HashSet<Following>();
}
[InverseProperty("User")]
public virtual ICollection<Following> Followings { get; set; }
[InverseProperty("FollowingUser")]
public virtual ICollection<Following> Followers { get; set; }
}