2013-06-20 32 views
0

我目前工作的一個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對象時執行的函數,因爲附件存儲在文件系統中,所以我需要確保文件被刪除。

+0

那麼它是你想要刪除的磁盤上的物理文件? –

+1

這是9小時前問的。 http://stackoverflow.com/questions/17214008/delete-a-file-from-database-and-file-system – qujck

回答

1

數據庫通常不會通知應用程序在數據更改時通知他們。如果你設計你的數據庫那麼它會容易得多,所以正在管理附件文件,而不是你的應用程序。

我不確定你使用的數據庫,但如果你使用的是Microsoft SQL Server,你應該使用FileStream data type