類型「System.StackOverflowException」未處理的異常出現在mscorlib.dll
確保你沒有無限循環或無限遞歸。C# - 實體框架 - 類型「System.StackOverflowException」未處理的異常出現在mscorlib.dll
下面的代碼被稱爲這個方法的成功:
internal static List<RivWorks.Model.Negotiation.ProductsSold> GetProductsSoldByCompany(Guid CompanyID)
{
var ret = from a in _dbRiv.ProductsSold where a.Company.CompanyId == CompanyID select a;
return ret.ToList();
}
調用它進入實體模型,並嘗試填充所有外國鍵入對象(子對象)的回報。模式是[1公司有0到多個產品銷售]。出於某種原因,呼叫到下面的代碼只是本身級聯:
[global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute("RIV_Model", "FK_ProductsSold_Company", "Company")]
[global::System.Xml.Serialization.XmlIgnoreAttribute()]
[global::System.Xml.Serialization.SoapIgnoreAttribute()]
[global::System.Runtime.Serialization.DataMemberAttribute()]
public Company Company
{
get
{
return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<Company>("RIV_Model.FK_ProductsSold_Company", "Company").Value;
}
set
{
((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<Company>("RIV_Model.FK_ProductsSold_Company", "Company").Value = value;
}
}
/// <summary>
/// There are no comments for Company in the schema.
/// </summary>
[global::System.ComponentModel.BrowsableAttribute(false)]
[global::System.Runtime.Serialization.DataMemberAttribute()]
public global::System.Data.Objects.DataClasses.EntityReference<Company> CompanyReference
{
get
{
return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<Company>("RIV_Model.FK_ProductsSold_Company", "Company");
}
set
{
if ((value != null))
{
((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.InitializeRelatedReference<Company>("RIV_Model.FK_ProductsSold_Company", "Company", value);
}
}
}
正如你可以看到,第一種方法使得第二種方法的調用。第二種方法似乎無休止地稱呼自己。
如何在EF中修復此問題?
在我看來,像你映射的問題 – hackerhasid 2010-01-14 22:04:12
所有完全限定的名稱是什麼?它們使得理解發生的事情變得不必要地困難。 – 2010-01-14 22:06:11
完全合格的名稱來自MS代代EF ... – 2010-01-14 22:08:50