我正在阅读这篇博客文章:
我喜欢他们如何制作一个界面,为您提供所有基本的 CRUD 查询,您可以在所有实体/表中使用它。
这也可以用 linqtosql 来完成吗?
代码:
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);
}
}
最佳答案
是的,有several尝试使用 LINQ to SQL 实现此模式。
关于c# - 如何使用 linq2sql 模拟 nhibernate 存储库模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1020147/