我有一個非常奇怪的問題,使用最新的EF 4.1與CodeFirst,我認爲這是來自我有一對一的關係。實體框架4.1 CodeFirst問題MVC
這個問題很奇怪,我有兩個不相關的控制器與不相關的實體,允許我列出並保存實體的ICollection。
http://localhost:51638/DailyHours/Edit/1 and
http://localhost:51638/HoursRemaining/Edit/1
兩者都單獨工作。例如,我先輸入一個,編輯並保存(工作)。然後我輸入第二個,編輯並保存,它不起作用。我得到的錯誤是:
參數字典包含參數「dailyHours」的方法「System.Web.Mvc.ActionResult編輯(的Int32,了System.Collections.Generic.ICollection
1[App.Domain.DailyHours])' in 'App.Web.Controllers.DailyHoursController'. The dictionary contains a value of type 'System.Collections.Generic.List
1應用的無效條目。 Domain.HoursRemaining]」,但參數需要類型的值‘System.Collections.Generic.ICollection`1 [App.Domain.DailyHours]’參數名:參數
如果我顛倒的順序我編輯並保存我得到相同的錯誤,但與DailyHours和HourRemaining相反。
The ke在波蘇斯Y的方面是:
public class Task
{
[Key]
public int TaskId { get; set; }
public virtual HoursRemaining HoursRemaining { get; set; }
}
public class HoursRemaining
{
[Key]
public int TaskId { get; set; }
public virtual Task Task { get; set; }
}
DailyHours必須或者這些沒有直接的關係:
public class DailyHours
{
[Key]
public int DailyHoursId { get; set; }
public virtual Sprint Sprint { get; set; }
}
我已經加入我的上下文的OnModelCreating代碼建立在一對一的關係的原則:
modelBuilder.Entity<Task>().HasOptional(h => h.HoursRemaining).WithRequired(t => t.Task);
我根本無法解決這個問題。任何幫助將不勝感激。
感謝
戴維