种子方法AddOrUpdate崩溃Visual Studio

时间:2015-10-20 08:31:14

标签: c# entity-framework visual-studio-2012

我的种子方法在其他表上使用AddOrUpdate时工作正常,但这段代码特别会在每次运行时崩溃Visual Studio。

context.GoogleCategories.AddOrUpdate(
    p => p.ID,
    new GoogleCategory { ParentID = null, name = "Clothing & Accessories" }
);

以下是模型定义:

[Table("GoogleCategory")]
public class GoogleCategory
{
    public GoogleCategory()
    {
        this.Parent = new GoogleCategory();
    }

    public int ID { get; set; }
    public string name { get; set; }
    public Nullable<int> ParentID { get; set; }

    public virtual GoogleCategory Parent { get; set; }
}

迁移中创建了什么:

CreateTable("dbo.GoogleCategory",
    c => new
    {
        ID = c.Int(nullable: false, identity: true),
        name = c.String(),
        ParentID = c.Int(),
    })
    .PrimaryKey(t => t.ID)
    .ForeignKey("dbo.GoogleCategory", t => t.ParentID)
    .Index(t => t.ParentID);

有什么想法吗?有一个事件查看器日志,但它没有显示我能看到的值得注意的信息。

Faulting application name: devenv.exe, version: 11.0.61219.0, time stamp: 0x55cdaf21
Faulting module name: clr.dll, version: 4.0.30319.34209, time stamp: 0x5348961e
Exception code: 0xc00000fd
Fault offset: 0x001a149e
Faulting process id: 0x1b48
Faulting application start time: 0x01d10b10520f2a40
Faulting application path: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Report Id: 8b926474-7706-11e5-aaf4-0024810b020a

1 个答案:

答案 0 :(得分:0)

很抱歉发布我自己的回答我应该先考虑一下。

创建GoogleCategory时出现了堆栈溢出异常,因为在构造函数中它正在尝试创建一个新的GoogleCategory(duh),因此显然只是旋转和旋转。

这确实意味着种子方法中的StackOverflowExceptions会使Visual Studio 2012崩溃而不是报告错误。