views:

42

answers:

1

Hi!

I am using ASP.NET MVC + LinqToSQL.

There is attachment model in my application. I need <IEnumerate>Attachment Attachments in several models. I don't wasn't to create different attachment models for different parent classes. Is there simple way to do it?

A: 

Do you mean that you want to use attachments in more places in your model? For example for Employee and for Customer objects? Do you mean something like:

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();
    }
}
Ole Lynge