entity framework - MVC4 EF Database Creation and Seeding Issue -
i getting update error when trying seed database. not sure if structure correctly setup create casefile contains basic information, create more complex file creating ot or pt casefile linked casefile (i hope semi-understandable)
i order make little easier view data i'm linking directory of code , stacktrace error getting. happens when add casefile code in seed method of configuration.cs file. somewhere hanging on old definition foreign key relationship between casefile , keywordid , settingid there in incarnation of class removed.
i tried delete database , used package manager add-migration initial gave me file '201308191626305_initial.cs' has these foriegn keys created. tried manually remove these file before running 'update-database -verbose' still produces errors complaining keyword-keywordid in stack track. tables build correctly , populated except casefile table gets created correctly not populated.
updating source files here. large files...
namespace mcpd_v3.migrations { using system; using system.data.entity.migrations; public partial class initial : dbmigration { public override void up() { createtable( "dbo.casefiles", c => new { casefileid = c.int(nullable: false, identity: true), userid = c.int(nullable: false), clientid = c.int(nullable: false), ptcasefileid = c.int(), otcasefileid = c.int(), submitted = c.boolean(nullable: false), postable = c.boolean(nullable: false), setting_settingid = c.int(), keyword_keywordid = c.int(), }) .primarykey(t => t.casefileid) .foreignkey("dbo.clients", t => t.clientid, cascadedelete: true) .foreignkey("dbo.settings", t => t.setting_settingid) .foreignkey("dbo.userprofile", t => t.userid, cascadedelete: true) .foreignkey("dbo.otcasefiles", t => t.otcasefileid) .foreignkey("dbo.ptcasefiles", t => t.ptcasefileid) .foreignkey("dbo.keywords", t => t.keyword_keywordid) .index(t => t.clientid) .index(t => t.setting_settingid) .index(t => t.userid) .index(t => t.otcasefileid) .index(t => t.ptcasefileid) .index(t => t.keyword_keywordid); ... createtable( "dbo.keywords", c => new { keywordid = c.int(nullable: false, identity: true), name = c.string(), expanded = c.string(), }) .primarykey(t => t.keywordid); } public override void down() { dropindex("dbo.clients", new[] { "settingid" }); dropindex("dbo.clients", new[] { "genderid" }); dropindex("dbo.casefiles", new[] { "keyword_keywordid" }); dropindex("dbo.casefiles", new[] { "ptcasefileid" }); dropindex("dbo.casefiles", new[] { "otcasefileid" }); dropindex("dbo.casefiles", new[] { "userid" }); dropindex("dbo.casefiles", new[] { "setting_settingid" }); dropindex("dbo.casefiles", new[] { "clientid" }); dropforeignkey("dbo.clients", "settingid", "dbo.settings"); dropforeignkey("dbo.clients", "genderid", "dbo.genders"); dropforeignkey("dbo.casefiles", "keyword_keywordid", "dbo.keywords"); dropforeignkey("dbo.casefiles", "ptcasefileid", "dbo.ptcasefiles"); dropforeignkey("dbo.casefiles", "otcasefileid", "dbo.otcasefiles"); dropforeignkey("dbo.casefiles", "userid", "dbo.userprofile"); dropforeignkey("dbo.casefiles", "setting_settingid", "dbo.settings"); dropforeignkey("dbo.casefiles", "clientid", "dbo.clients"); droptable("dbo.keywords"); droptable("dbo.files"); droptable("dbo.ptcasefiles"); droptable("dbo.otcasefiles"); droptable("dbo.userprofile"); droptable("dbo.settings"); droptable("dbo.genders"); droptable("dbo.clients"); droptable("dbo.casefiles"); }
here class file
using system; using system.collections.generic; using system.componentmodel.dataannotations.schema; using system.linq; using system.text; namespace mcpd_v3.models { public class casefile { public int casefileid { get; set; } public int userid { get; set; } public int clientid { get; set; } public int? ptcasefileid { get; set; } public int? otcasefileid { get; set; } public bool submitted { get; set; } public bool postable { get; set; } public virtual client client { get; set; } public virtual userprofile user { get; set; } public virtual otcasefile otcasefile { get; set; } public virtual ptcasefile ptcasefile { get; set; } } } using system; using system.collections.generic; using system.linq; using system.text; namespace mcpd_v3.models { public class keyword { public keyword() { this.casefiles = new hashset<casefile>(); } public int keywordid { get; set; } public string name { get; set; } public string expanded { get; set; } public icollection<casefile> casefiles { get; set; } } }
any appreciated.
Comments
Post a Comment