c# - How to properly add a foreign key from my own model to the EF Userprofile? -


my model classes first:

public class person {     [required, key]     public int id { get; set; }     [required]     public string name { get; set; }     [required]     public string learntskillsandlevelofskills { get; set; }     public string profileimage { get; set; }     public string city { get; set; }     public string phonenr { get; set; }     [required]     public string email { get; set; }     public string hobbys { get; set; }     public string skillstolearn { get; set; }     public string stand { get; set; }     public int yearsofworkexperience { get; set; }     public string hobbyprojectictrelated { get; set; }     public string extrainfo { get; set; }     public string summary { get; set; }      public int userid { get; set; }     [foreignkey("userid")]     public virtual userprofile profile { get; set; }  } 


 [table("userprofile")]     public class userprofile     {         [key]         [databasegeneratedattribute(databasegeneratedoption.identity)]         public int userid { get; set; }         public string username { get; set; }          public nullable<int> id { get; set; }         public virtual person personprofile { get; set; }      } 

when run gives me exception: principal end of association must explicitly configured

i've searched error doesn't clarify me... absolutely have no clue how fix this. want link person class userprofiles can create login mechanism automatically lets 1 person makes account on site 1 profile edit own information. he's not allowed modify other people accounts.

i hope makes problem clear , can me :). i'm using ef 6 btw , error in class initializesimplemembershipattribute comes standard mvc example of asp.net

greetings , in advance,
marijn

i managed working these codes in models:

[table("userprofile")] public class userprofile {      [key, databasegeneratedattribute(databasegeneratedoption.identity)]      public int userid { get; set; }      public string username { get; set; }       public virtual person personprofile { get; set; } } 


public class person {     [foreignkey("profile"), key]     public int userid { get; set; }     [required]     public string name { get; set; }     [required]     public string learntskillsandlevelofskills { get; set; }     public string profileimage { get; set; }     public string city { get; set; }     public string phonenr { get; set; }     [required]     public string email { get; set; }     public string hobbys { get; set; }     public string skillstolearn { get; set; }     public string stand { get; set; }     public int yearsofworkexperience { get; set; }     public string hobbyprojectictrelated { get; set; }     public string extrainfo { get; set; }     public string summary { get; set; }      public userprofile profile { get; set; } } 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -