I have 2 entities: Reports and FileRequests. There is a many-to-many relationship between these.
So Report.cs has
public virtual ICollection<FileRequest> FileRequests { get; set; }
And FileRequest.cs has
public ICollection<Report> Reports { get; set; }
Entity Framework has generated a join table (FileRequestReports) and cascade delete always works for the join table entries. What I want to happen is deleting a filerequest deletes the associated reports, but deleting a report DOES NOT delete the associated filerequests. The associated join table entries should always be deleted.
Note: the ManyToManyCascadeDeleteConvention is on.
Is there a relatively easy way to do with with EF and cascade delete?
Thanks in advance.
FileRequestReports
? Usually auto-generated many-to-many tables use the Ids of the two related tables as keys. If you delete one end of the relationship, it is set up to cascade deletes because the foreign key restraint would fail. In order to make this work, you would need to create your ownFileRequestReport
entity, give it a unique key, make theReportId
field required, and make theFileRequestId
nullable. - Sam