种子自引用表MVC 4出错

时间:2016-07-27 15:55:00

标签: c# asp.net-mvc asp.net-mvc-4

我跟随this tutorial创建了一个自引用表。我在种子方法中有这个:

            var menuItems = new List<Subcomponent>{
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 1},
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 2},
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 3},
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 4},
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 5},
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 1, ParentSubcomponentId = 1},
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 2, ParentSubcomponentId = 1},
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 3, ParentSubcomponentId = 1},
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 1, ParentSubcomponentId = 7},
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 2, ParentSubcomponentId = 7},
    new Subcomponent{TipoSub = "Testes", NomeSub = "Testes", NotaMinimaSub = 9, PesoSub = 10, Ordem = 3, ParentSubcomponentId = 7}
};
            menu.SubcomponentsComp = menuItems;
            context.Components.AddOrUpdate(m => m.SubcomponentsComp, menu);
            context.SaveChanges();
        }

就像在教程中一样。但是当我尝试更新数据库时它会出现此错误:

  

无法创建类型&#39; SGP.Models.Subcomponent&#39;的常量值。   此处仅支持原始类型或枚举类型   上下文。

任何人都知道为什么会出现此错误?感谢

0 个答案:

没有答案