gpt4 book ai didi

c# - 自动数据访问层

转载 作者:行者123 更新时间:2023-11-30 14:04:43 24 4
gpt4 key购买 nike

我根本厌倦了编写数据访问层。我认为这是一种无聊且毫无意义的努力。我设想了一个开发环境,我可以在其中创建我的实体/模型并开始构建应用程序。写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 Server
  • sqlite

...但是该理论适用于任何数据存储库

有没有人遇到现成的解决方案,或者我是否必须通过编写比我想动摇的更多的数据访问层来解决问题。

注意:我知道 ORM,我想要一些可以消除编写任何 DAL 或存储过程的要求的东西。

最佳答案

看看 NHibernate、CaSTLe ActiveRecord、SubSonic、LinqToSql,...

您说您了解 ORM,但它们几乎完全符合您的问题要求,至少在可能的范围内。

关于c# - 自动数据访问层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1272051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com