Một ngoại lệ unhandled của loại 'System.StackOverflowException' xảy ra ở mscorlib.dll
Hãy chắc chắn rằng bạn không có một vô hạn vòng lặp hoặc đệ quy vô hạn.C# - Entity Framework - Một ngoại lệ unhandled của loại 'System.StackOverflowException' xảy ra ở mscorlib.dll
Mã dưới đây được gọi vào thành công của phương pháp này:
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();
}
On sự trở lại nó gọi vào Entity Model và cố gắng để cư tất cả các đối tượng keyed nước ngoài (đối tượng trẻ em). Lược đồ là [1 Công ty có 0 đến nhiều Sản phẩmSold]. Vì một lý do nào đó, lệnh gọi vào mã sau chỉ cần xếp vào chính nó:
[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);
}
}
}
Như bạn có thể thấy, phương pháp đầu tiên thực hiện cuộc gọi đến phương pháp thứ hai. Phương pháp thứ hai dường như tự gọi là vô tận.
Làm cách nào để khắc phục sự cố này trong EF?
nhìn tôi giống như một vấn đề với ánh xạ của bạn – hackerhasid
Có gì với tất cả các tên đủ điều kiện? Họ làm cho nó không cần thiết khó khăn để hiểu những gì đang xảy ra. –
các tên đủ điều kiện là từ thế hệ mã của MS cho EF ... –