Skip to content

Unable to remove entity due to bad association syncronization #36

@alex-kulakov

Description

@alex-kulakov

Say there are two entities connected to each other following way

[HierarchyRoot]
 public class Job : Entity
 {
   [Field, Key]
   public long Id { get; private set; }
   [Field]
   [Association(PairTo = nameof (JobTechnology.ReqiredJob), OnTargetRemove = OnRemoveAction.Clear, OnOwnerRemove = OnRemoveAction.Cascade)]
   public JobTechnology Technology { get; set; }

   public Job(Session session)
     : base(session)
   {
   }
 }

 [HierarchyRoot]
 public class JobTechnology : Entity
 {
   [Field, Key]
   public long Id { get; private set; }
   [Field(Nullable = false)]
   public Job ReqiredJob { get; private set; }

   public JobTechnology(Session session, Job job)
     : base(session)
   {
     ReqiredJob = job;
   }
 }

and try to remove referenced JobTechnology instance like job.Technology.Remove() leads to the error similar to following

Xtensive.Orm.ReferentialConstraintViolationException : SQL error occured.
    Storage error details 'Entity: Job; Field: Technology.Id (FieldInfo);'
    SQL error details 'Type: ReferentialConstraintViolation; Database: DO-Tests; Table: Job; Column: Technology.Id; Constraint: FK_Job_Technology_JobTechnology;'
    Query 'DELETE FROM [dbo].[JobTechnology] WHERE ([JobTechnology].[Id] = @p1_0); [p1_0='2']'
    Original message 'The DELETE statement conflicted with the REFERENCE constraint "FK_Job_Technology_JobTechnology". The conflict occurred in database "DO-Tests", table "dbo.Job", column 'Technology.Id'.
    The statement has been terminated.'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions