我基本上生病写数据访问层。我认为这是一个无聊而毫无意义的努力。我设想一个开发环境,我可以创建我的实体/模型并开始构建应用程序。编写DAL,程序等所花费的时间......只是满足了我对项目的热情。自动数据访问层
我想要的是我的数据的通用储存库接口。喜欢的东西:
public interface IRepository
{
//Get individual TEntity item by id
TEntity GetItem<TIdentifier, TEntity>(TIdentifier id);
//Get individual TEntity item by the expression
TEntity GetItem<TIdentifier, TEntity, TArg>(Expression<Func<TArg, TEntity>> expression);
//Get individual TEntity item by the expression
TEntity GetItem<TIdentifier, TEntity, TArg1, TArg2>(Expression<Func<TArg1, TArg2, TEntity>> expression);
//Get all TEntity items
IList<TEntity> GetList<TEntity>();
//Get all TEntity items, filtered by the expression
IList<TEntity> GetList<TEntity, TArg>(Expression<Func<TArg, IList<TEntity>>> expression);
//Get all TEntity items, filtered by the expression
IList<TEntity> GetList<TEntity, TArg1, TArg2>(Expression<Func<TArg1, TArg2, IList<TEntity>>> expression);
TIdentifier CreateItem...
bool UpdateItem...
bool DeleteItem...
}
我的东西特别感兴趣的是将工作
- Azure的数据服务
- SQL服务器
- SQLite的
...但理论适用于任何数据存储库
有没有人遇到过现成的解决方案,还是我必须通过编写更多的数据访问层来解决这个问题,这比我曾经想过的要坚持一些。
注:我知道ORM的,我想要的东西,删除要求编写的任何DAL或存储特效。
难道我仍然不得不为我所有的实体编写特效吗? – grenade 2009-08-13 13:50:09
不,你不必写存储过程,你可以编写LINQ语句。那么你的所有代码都在C#中。 – mkchandler 2009-08-13 13:51:26
如果你的编程教条是编写存储过程,那么是的,你将不得不编写它们。我成功实现了使用LinqToSql作为没有存储过程的ORM的Web窗体模型。 – JustLoren 2009-08-13 13:53:07