c# - Entity framework 6: referring to UserProfile -


i trying write asp mvc app custom dbinitializer, i'm getting error:

additional information: member identity 'mailmail.models.maildbcontext.video_userprofile' not exist in metadata collection.

i have video class:

public class video : entity {     public string name { get; set; }     public string path { get; set; }     public virtual userprofile userprofile { get; set; } } 

and dbinitializer:

 public class maildbinitializer : dropcreatedatabasealways<maildbcontext>     {         protected override void seed(maildbcontext context)         {             userscontext usercontext = new userscontext();              if (!webmatrix.webdata.websecurity.initialized)             {                 websecurity.initializedatabaseconnection("defaultconnection", "userprofile", "userid", "username", autocreatetables: true);             }               var mongol1 = new { email="mail2@mail", username="tom"};             var mongol2 = new { email = "mail@mail", username = "karola" };             websecurity.createuserandaccount(mongol1.username, "secret", mongol1);              task<userprofile> user1task = usercontext.userprofiles.singleordefaultasync(o => o.username == mongol1.username);             user1task.wait();             userprofile user1 = user1task.result;              websecurity.createuserandaccount(mongol2.username, "123456", mongol2);             task<userprofile> user2task = usercontext.userprofiles.singleordefaultasync(o => o.username == mongol2.username);             user2task.wait();             userprofile user2 = user1task.result;                 video video1 = new video() {name="moje wideo", userprofile=user1, path = "~/app_data/"+user1.userid+"/video1"};             video video2 = new video() { name = "moje wideo", userprofile = user1, path = "~/app_data/" + user1.userid + "/video2" };             video video3 = new video() { name = "moje wideo", userprofile = user2, path = "~/app_data/" + user2.userid + "/video3" };             video video4 = new video() { name = "moje wideo", userprofile = user2, path = "~/app_data/" + user2.userid + "/video4" };              context.videos.add(video1);  //here ocures error!             context.videos.add(video2); 

i think might have different contexts. right?

the problem had 2 different context, evn tho both pointing same database. solution was: i've copied

 public dbset<userprofile> userprofiles { get; set; } 

to main dbcontext class. solved problem :-)


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -