c# - The .mdf is not being created in App_Data -


i working on c# asp.net web forms project in visual studio ultimate 2013 while following http://goo.gl/1hk73 tutorial (but not doing exact same project). however, not make create .mdf file in app_date.

i have created entity classes, dbcontext, seeded 1 of table single item, added connectionstring web.config:

<add name="testingsystem" connectionstring="data source (localdb)\v11.0;attachdbfilename=|datadirectory|\studenttestingsystem.mdf;integrated security=true" providername="system.data.sqlclient" /> 

, , initialized database in global.asax.cs application_start() method:

database.setinitializer(new testingsystemdatabaseinitializer()); 

i have looked similar problems, nothing worked me (i had done or did not work).

i have refreshed app_data folder in solution explorer , used show files option nothing changed.

my testingsystemdatabaseinitializer:

using system.collections.generic; using system.data.entity;  namespace student_testing_system.models {     public class testingsystemdatabaseinitializer :     dropcreatedatabaseifmodelchanges<testingsystemcontext>     {         protected override void seed(testingsystemcontext context)         {             var root = new category()             {                 categoryid = 0,                 categoryname = "root",                 description = "default category",                 parentid = null,                 parent = null,             };              context.categories.add(root);         }     } } 

context:

public class testingsystemcontext : dbcontext {     public testingsystemcontext()         : base("testingsystem")     {      }      public dbset<question> questions { get; set; }     public dbset<category> categories { get; set; }     public dbset<template> templates { get; set; }     public dbset<test> tests { get; set; }     public dbset<studygroup> studygroups { get; set; } } 

moreover when updating database via update-database in pm errors:
entitytype 'identityuserlogin' has no key defined. define key entitytype. entitytype 'identityuserrole' has no key defined. define key entitytype.

both of classes part of entityframework , don't have data annotations [key] i'm not sure how solve this.

identityuserlogin:

public class identityuserlogin {     public identityuserlogin();      public virtual string loginprovider { get; set; }     public virtual string providerkey { get; set; }     public virtual identityuser user { get; set; }     public virtual string userid { get; set; } } 

identityuserrole:

public class identityuserrole {     public identityuserrole();      public virtual identityrole role { get; set; }     public virtual string roleid { get; set; }     public virtual identityuser user { get; set; }     public virtual string userid { get; set; } } 

to update database open tools->library package manager->package manager console , type in opened console

update-database 

to restart localdb service open "developer command prompt vs.net" under start/programs menu->all programs->visual studio->visual studio tools

run following commands:

sqllocaldb.exe stop v11.0 sqllocaldb.exe delete v11.0 

after execute "update-database" again.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -