Entity Framework - Seed AddOrUpdate с многостолбцовым индексом в качестве идентификатора
Я пытаюсь заполнить базу данных, используяcontext.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
});
Можно ли сравнивать многостолбцовые индексы при вставке начальных данных?