几种模型中的附件属性

时间:2009-04-21 13:51:36

标签: asp.net-mvc linq-to-sql

我正在使用ASP.NET MVC + LinqToSQL。

我的申请中有附件模型。我在几个模型中需要<IEnumerate>Attachment Attachments。我不是不为不同的父类创建不同的附件模型。有简单的方法吗?

1 个答案:

答案 0 :(得分:0)

您是否想要在模型中的更多位置使用附件?例如EmployeeCustomer个对象?你的意思是:

public class Attachment { /* Various properties... */ }
public class Attachments : List<Attachment>
{
    public void DoSomething()
    {
        foreach (Attachment attachment in this)
            DoSomethingToAttachment(attachment);
    }
}
public interface IAttachmentHandler
{
    void HandleAttachments();
}
public class Employee : IAttachmentHandler
{
    private Attachments _attachments;
    public void HandleAttachments()
    {
        _attachments.DoSomething();
    }
}

public class Customer : IAttachmentHandler
{
    private Attachments _attachments;
    public void HandleAttachments()
    {
        _attachments.DoSomething();
    }
}