本文介绍了C# - 实体框架 - 在mscorlib.dll中发生类型为“System.StackOverflowException”的未处理异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在此方法的成功中被调用:

The below code is called on a success of this method:

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();
}

在返回时调用Entity Model并尝试填充所有外键对象(子对象)。该模式是[1公司有0到多个产品销售]。由于某些原因,调用以下代码只是级联它:

On the return it calls into the Entity Model and tries to populate all foreign keyed objects (child objects). The schema is [1 Company has 0 to many ProductsSold]. For some reason, the call into the following code just cascades on itself:

[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);
        }
    }
}

如你所见,第一种方法调用第二种方法。

As you can see, the first method makes a call to the second method. The second method seems to call itself endlessly.

如何在EF中修复这个问题?

How do I fix this in EF?

推荐答案

从头开始删除和重建我的模型3次后,堆栈溢出是神奇的消失。 < grrrrr />

After 3 times at deleting and rebuilding my model from scratch, the stack overflow is magically gone. <grrrrr />

将线条上的某个地方的向导错误刷新。

Chalk it up to a bad wizard error somewhere along the line.

这篇关于C# - 实体框架 - 在mscorlib.dll中发生类型为“System.StackOverflowException”的未处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 00:36