views:

114

answers:

1

I was reading this blog entry:

http://blogs.hibernatingrhinos.com/nhibernate/archive/0001/01/01/the-repository-pattern.aspx

I like how they made a interface that has all the basic CRUD queries for you, and you can use it accross all your entities/tables.

Can this also be done with linqtosql as well?


Code:

public class Repository<T> : IRepository<T>
{
    public ISession Session { get { return UnitOfWork.CurrentSession; } }
    public T GetById(int id)
    {
        return Session.Get<T>(id);
    }

    public ICollection<T> FindAll()
    {
        return Session.CreateCriteria(typeof(T)).List<T>();
    }

    public void Add(T product)
    {
        Session.Save(product);
    }

    public void Remove(T product)
    {
        Session.Delete(product);
    }

}
A: 

Yes, there are several attempts to implement this pattern using LINQ to SQL.

Jason