.net - Sequence Contains No Matching Elements Entity Seed Error -
previously had entity database working. deleted it, out of haste, went run program again (thinking should recreate , repopulate db did before). however, time got weird error: system.invalidoperationexception: sequence contains no matching element
on line of code in "sampledata.cs" file (location seed data comes from):
52: new list<card>
any idea happening here?
app start method:
protected void application_start() { system.data.entity.database.setinitializer(new gostopprimer.models.sampledata()); bundleconfig.registerbundles(bundletable.bundles); arearegistration.registerallareas(); registerglobalfilters(globalfilters.filters); registerroutes(routetable.routes); }
gostopentities.cs
public class gostopentities : dbcontext { public dbset<card> cards { get; set; } public dbset<cardtype> cardtypes { get; set; } public dbset<month> months { get; set; } public dbset<special> specials { get; set; } }
card.cs model
public class card { public int cardid { get; set; } public int cardtypeid { get; set; } public int monthid { get; set; } public string name { get; set; } public string cardarturl { get; set; } public virtual cardtype cardtype { get; set; } public virtual month month { get; set; } public virtual special special { get; set; } }
snippet of sampledata.cs
using system; using system.collections.generic; using system.linq; using system.web; using system.data.entity; namespace gostopprimer.models { public class sampledata : dropcreatedatabaseifmodelchanges<gostopentities> { protected override void seed(gostopentities context) { var cardtypes = new list<cardtype> { new cardtype { name = "kwang" }, }; var months = new list<month> { new month { name = "january" }, }; var specials = new list<special> { new special { name = "none" }, }; new list<card> { new card { name = "pine", cardtype = cardtypes.single(c => c.name == "kwang"), month = months.single(m => m.name == "january"), cardarturl = "/content/images/cards/jan1.gif", special = specials.single(s => s.name == "none") }, new card { name = "willow/rain", cardtype = cardtypes.single(c => c.name == "kwang"), month = months.single(m => m.name == "january"), cardarturl = "/content/images/cards/dec4.gif", special = specials.single(s => s.name == "none") }, }.foreach(c => context.cards.add(c)); } } }
"i had forgotten add new "special" field".
Comments
Post a Comment