This question is locked. New answers and comments are not allowed.
I am trying to insert a new item into the database using OpenAccess.
Here is my code:
It works fine if i insert only the organisation but if i first add a new office to the organisation and then try to insert it it fails.
I get the following error:
failed: Telerik.OpenAccess.RT.sql.SQLException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_OrganisationOffice". The conflict occurred in database "Squirrel", table "dbo.Organisations", column 'Id'.
What can i do to avoid this?
Here is my code:
EntitiesModel context =
new
EntitiesModel();
Organisation myOrganisation =
new
Organisation();
myOrganisation.GroupId = 1;
myOrganisation.Details_Name =
"testDDDDDDDDDDDDDDDD"
;
myOrganisation.VisibilityTypeId = 1;
myOrganisation.UserId = 1;
myOrganisation.Core_Position = 99;
myOrganisation.Core_StateFlag = 0;
myOrganisation.Core_CreationDate = DateTime.UtcNow;
myOrganisation.Core_ModifiedDate = DateTime.UtcNow;
Office myOffice =
new
Office();
myOffice.Core_Position = 99;
myOffice.Core_StateFlag = 0;
myOffice.Core_CreationDate = DateTime.UtcNow;
myOffice.Core_ModifiedDate = DateTime.UtcNow;
myOrganisation.Offices.Add(myOffice);
context.Add(myOrganisation);
context.SaveChanges();
It works fine if i insert only the organisation but if i first add a new office to the organisation and then try to insert it it fails.
I get the following error:
failed: Telerik.OpenAccess.RT.sql.SQLException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_OrganisationOffice". The conflict occurred in database "Squirrel", table "dbo.Organisations", column 'Id'.
What can i do to avoid this?