1
Vote

Scaffold controller crashes Visual Studio when recursive foreign key is present

description

Given the following model, the command "scaffold controller Subject" will crash visual studio, presumably due to a stack overflow. Removing the ParentId and Parent properties resolves the issue.

public class Subject
{
    public int SubjectId { get; set; }

    [Required]
    public string Name { get; set; }

    public int ParentId { get; set; }
    public virtual Subject Parent { get; set; }

}
I am using MvcScaffolding v 1.0.6

comments

jostevenson wrote Nov 13, 2012 at 3:21 AM

Have you tried adding the ForeignKey attribute before Parent:

[ForeignKey("ParentId")] public virtual Subject Parent { get; set; }


Steve Sanderson talks about this a little bit here:
http://channel9.msdn.com/Series/mvcConf/mvcConf-2-Steve-Sanderson-MvcScaffolding
@17:24