entity framework - I am getting error of conflict in asp.net MVC5 -


i getting error of conflict in asp.net mvc5

here model class of form model

[databasegenerated(databasegeneratedoption.identity)]         [key]         public guid formid { get; set; }         public guid entityblockid { get; set; } // linktoentityblockid         public virtual entityblock entityblock { get; set; } 

here model class of entityblock model

[databasegenerated(databasegeneratedoption.identity)]         [key]         public guid entityblockid { get; set; }          public virtual icollection<form> form { get; set; } 

and inserting value below:

formstaticmethodscontroller formstaticmethodscontrollerobj = new formstaticmethodscontroller();          form form = new form();                     form.entityblockid = linktoblockid;     formstaticmethodscontrollerobj.createform(form); 

method is:

 public guid createform(form form)             {                 db.forms.add(form);                 db.savechanges();                  return form.formid;             } 

an error is:

the insert statement conflicted foreign key constraint "fk_dbo.form_dbo.entityblock_entityblockid". conflict occurred in database "aspnet-planetskool-20150303080110", table "dbo.entityblock", column 'entityblockid'. statement has been terminated.

enter image description here

if have entityblockiddefined foreign key value entityblock, should link entityblock property link field entityblockid using foreignkeyattribute:

    [databasegenerated(databasegeneratedoption.identity)]     [key]     public guid formid { get; set; }     public guid entityblockid { get; set; } // linktoentityblockid      [foreignkey("entityblockid")]     public virtual entityblock entityblock { get; set; } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -