I'm currently working on an ASP.NET MVC project that allows the user to upload files to the server, and associate them with another object
public class FileAttachment
{
[Key]
public int Id { get; set; }
public string Title { get; set; }
public string ContentType { get; set; }
public string Extension { get; set; }
[ForeignKey("Donor")]
public int DonorId { get; set; }
public virtual Donor Donor { get; set; }
}
public class Donor
{
[Key]
public int Id { get; set; }
// .....
public virtual List<FileAttachment> Attachments { get; set; }
}
What I'm wondering is if there's a way to specify a function for Entity Framework to execute when a Donor or FileAttachment object is removed from the DbSet, because the attachments are stored in the file system so I need to make sure the file gets deleted.