【发布时间】:2010-10-12 21:24:06
【问题描述】:
我有一个存储库基类,它从我的 mvc 应用程序中的控制器调用
每个控制器都有自己的存储库
喜欢这个
public class ServiceRepository : Bluegrass.Mvc.RepositoryBase<Models.Service>
{
public ServiceRepository()
{
this._db = new iSppms.Models.iSppmsDataContext();
}
}
然后像被使用一样
internal DataAccess.ServiceRepository repository =
new iSppms.DataAccess.ServiceRepository();
public ActionResult Index()
{
var viewData = new ViewData.ServiceIndexViewData(
repository.GetItems<Models.Service>());
return View(viewData);
}
我想做的不是传递模型,因为 RepositoryBase 已经是 Models.Service 类型
我正在寻找一种更好的方式来构建它。
public class RepositoryBase<T> where T : class
{
public DataContext _db;
public List<T> GetItems<T>() where T : class, Interfaces.IModel
{
var table = _db.GetTable<T>();
var data = table.Where(t => !t.Deleted);
return data.ToList();
}
【问题讨论】: