當我有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.
有人可以對此發光嗎?
是您最後一次編輯答案了嗎?也許你可以將它轉換爲答案並將其標記爲已接受。 – 2013-02-16 10:15:39