8
context.AddOrUpdate
メソッドを使用してデータベースをシードしようとしていますが、マルチカラムインデックスに基づいて挿入されたデータをユニークにする必要があります。 Entity Framework - シードAddOrUpdate(識別子としてマルチカラムインデックスを使用)
[Table("climbing_grades")]
public class ClimbingGrade : EntityBase
{
/// <summary>
/// The name of the climbing grade, e.g.: 7a, VII, etc.
/// </summary>
[Index("IX_Name_GradeType", 1, IsUnique = true)]
public string Name { get; set; }
/// <summary>
/// Tries to display the average difficulty of the described grade.
/// Matching the different grades can be difficult because its always
/// a subjective rating and there exists no norm on converting grades.
/// </summary>
public double Difficulty { get; set; }
/// <summary>
/// The type of the grade. Will be the respective region rating.
/// e.g.: UUIA for most oft europe, YSD for USA, etc.
/// </summary>
[Index("IX_Name_GradeType", 2, IsUnique = true)]
public ClimbingGradeType GradeType { get; set; }
}
は現在、私は
AddOrUpdate
クライミンググレードの
Name
に基づいて、今私は私が重複する名前を挿入する必要がある時点でいます。
context.ClimbingGrades.AddOrUpdate(grade => /* Compare multi column index here?*/,
new ClimbingGrade
{
Name = "5a",
Difficulty = 4.75,
GradeType = ClimbingGradeType.FontainebleauBloc
},
new ClimbingGrade
{
Name = "5a",
Difficulty = 4.25,
GradeType = ClimbingGradeType.FontainebleauTraverse
});
シードデータを挿入するとマルチカラムインデックスを比較できますか?
「これは比較できるのですか?」とはどういう意味ですか?あなたは何をしたいのですか?繰り返し可能な値の一部のみを保持しますか? – JotaBe
データセットがデータベースに既に存在する場合は、マルチカラムインデックスを参照として使用したいと思います。 例:.AddOrUpdate(グレード=>グレード名==既存の名前&&グレード。グレードタイプ==既存のグレードタイプ) ' – Silthus