Entity Framework - Seed AddOrUpdate with multi column index as identifier

前端 未结 1 831
无人共我
无人共我 2021-02-15 01:43

I am trying to seed a database using the context.AddOrUpdate method, but the problem is that I need to make the inserted data unique based on a multi column index.<

相关标签:
1条回答
  • 2021-02-15 02:33

    You need to use anonymous type for specifying multiple columns. This also works without specifying the indicies.

    context.ClimbingGrades.AddOrUpdate(grade => new { grade.Name, grade.GradeType },
        new ClimbingGrade
        {
            Name = "5a",
            Difficulty = 4.75,
            GradeType = ClimbingGradeType.FontainebleauBloc
        },
        new ClimbingGrade
        {
            Name = "5a",
            Difficulty = 4.25,
            GradeType = ClimbingGradeType.FontainebleauTraverse
        });
    
    0 讨论(0)
提交回复
热议问题