views:

73

answers:

0

I am designing an app that will be using LINQ2SQL to persist the data in a database. I often use the Strategy pattern.

For instance, I may have a ClubMember object which can use different cost strategies like the following:

class ClubMember
{
    public String name { get; set; }
    public String email { get; set; }
    private IMembershipCostCalculator costCalculator;

    public ClubMember(IMembershipCostCalculator costCalculator)
    {
        this.costCalculator = costCalculator;
    }

    public int getMembershipCost()
    {
        return costCalculator.getMembershipCost();
    }
}

public interface IMembershipCostCalculator
{
    int getMembershipCost();
}

How would I persist an object like this to the database using LINQ2SQL? When getting the object out of the database how would LINQ know which IMembershipcostCalculator object should be injected?

Thanks, Matt