【发布时间】:2013-11-05 22:02:48
【问题描述】:
我目前正在开发一个 ASP.NET MVC 项目,该项目允许用户将文件上传到服务器,并将它们与另一个对象相关联
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; }
}
我想知道的是,是否有办法指定实体框架在从 DbSet 中删除 Donor 或 FileAttachment 对象时执行的函数,因为附件存储在文件系统中,所以我需要确保文件被删除。
【问题讨论】:
-
那么它是您要删除的磁盘上的物理文件吗?
-
这是 9 小时前提出的。 stackoverflow.com/questions/17214008/…
标签: c# asp.net-mvc entity-framework