このような2つのモデルがある場合:
public class PredictionGroup
{
[Key]
public Guid PredictionGroupId { get; set; }
public Guid? ResultPredictionId { get; set; }
[ForeignKey("ResultPredictionId")]
public Prediction ResultPrediction { get; set; }
public List<Prediction> Predictions { get; set; }
}
public class Prediction
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid PredictionId { get; set; }
[Required]
public Guid PredictionGroupId { get; set; }
[ForeignKey("PredictionGroupId")]
public PredictionGroup PredictionGroup { get; set; }
}
これが生成されます:
CreateTable(
"Website.PredictionGroups",
c => new
{
PredictionGroupId = c.Guid(nullable: false, identity: true),
ResultPredictionId = c.Guid(),
})
.PrimaryKey(t => t.PredictionGroupId)
.ForeignKey("Website.Predictions", t => t.ResultPredictionId)
.Index(t => t.ResultPredictionId);
CreateTable(
"Website.Predictions",
c => new
{
PredictionId = c.Guid(nullable: false, identity: true),
PredictionGroupId = c.Guid(nullable: false),
PredictionGroup_PredictionGroupId = c.Guid(),
})
.PrimaryKey(t => t.PredictionId)
.ForeignKey("Website.PredictionGroups", t => t.PredictionGroupId)
.ForeignKey("Website.PredictionGroups", t => t.PredictionGroup_PredictionGroupId)
.Index(t => t.PredictionGroupId)
.Index(t => t.PredictionGroup_PredictionGroupId);
これをデータベースに入力しようとすると、次のエラーが表示されます。Unable to determine the principal end of the 'Site.Data.Prediction_PredictionGroup' relationship. Multiple added entities may have the same primary key.
誰かがこれに光を当てることができますか?