views:

48

answers:

0

I have contracts for functionality in my repository that are implemented with linq-to-sql.

// IEvent was extracted from the generated linq-to-sql class
public partial class Event : IEvent
{
}

public class EventRepository : IEventRepository
{
    public void Add(IEvent e)
    {
        db.Events.InsertOnSubmit(e);
        db.SubmitChanges();
    }

    public List<IEvent> GetList()
    {
        var query = from e in db.Events
                    select e;

        return query.ToList();
    }
}

The linq-to-sql methods want the concrete type Event. Can I supply the concrete type through Ninject or is there another way to do this? Or if something like Structure Map or another framework supports this I would like to know that as well.


The nasty way I got this to work for now is following, but I would really like a clean way of doing this without introducing the dependency.

db.Events.InsertOnSubmit((Event)e);

return query.Cast<IEvent>().ToList();