c# - Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to NULL -


here function add row in db:

    public static void insertnote(string title, string text, int languageid)     {         var dbo = new userscontext();         models.noteform note = new noteform         {             text = text,             title = title,             languageid = languageid,             userid = websecurity.currentuserid         };         dbo.note.add(note);         dbo.savechanges();      } 

and model used:

public class noteform {     [required]     [stringlength(100, errormessage = "the {0} must @ least {2} characters long.", minimumlength = 6)]     [display(name = "title")]     public string title { get; set; }      [required]     [display(name = "text")]     public string text { get; set; }      [required]     [display(name = "language")]       public int languageid { get; set; }     [foreignkey("id")]     public virtual language language { get; set; }      [key]     public int id { get; set; }      public int userid { get; set; }  } 

at line :

dbo.savechanges(); 

i error:

cannot insert explicit value identity column in table when identity_insert set null

with debugger see language property

 public virtual language language { get; set; } 

is set null. that's reason why error. how solve problem ? can't initialize property, use navigate through table. in advance

asnwer given py3r3str. see above.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -