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.
if have entityblockid
defined 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
Post a Comment