2

Entity Framework では、複数の列に主キーを定義できます。

このようなもの

public class MyEntity
{
    [Key, Column(Order=0)]
    public int MyFirstKeyProperty { get; set; }

    [Key, Column(Order=1)]
    public int MySecondKeyProperty { get; set; }          
}

mongoDb でそのような動作を実現する方法はありますか?

4

1 に答える 1

-1

データベースに CompoundIndex を作成できます。以下のリンクで詳しく説明しています。

https://docs.mongodb.com/manual/core/index-compound/

C# では、この方法で作成できます

           grades.Indexes.CreateMany(Builders<MyCollection>.IndexKeys.Ascending(x => x.Name))

            //if you don't have mycollection, and your collection is of type IMongoCollection<BSonDocument> then you can use this

            grades.Indexes.CreateManyAsync("{ Name: 1 }","{ID:-1}");
于 2016-05-12T12:12:46.427 に答える