我基本上生病寫數據訪問層。我認爲這是一個無聊而毫無意義的努力。我設想一個開發環境,我可以創建我的實體/模型並開始構建應用程序。編寫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