简体   繁体   English

自动数据访问层

[英]Automatic Data Access Layer

I'm fundamentally sick of writing data access layers. 我从根本上讨厌写数据访问层。 I see it as a boring and pointless endeavour. 我认为这是无聊而毫无意义的努力。 I envisage a development environment where I can just create my Entities/Models and start building the application. 我设想一个开发环境,在这里我可以创建我的实体/模型并开始构建应用程序。 The time taken to write the DAL, procedures, etc... just eats my enthusiasm for a project. 编写DAL,过程等所花费的时间只会使我对项目充满热情。

What I want is a generic repository interface for my data. 我想要的是用于数据的通用存储库接口。 Something like: 就像是:

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...
}

I'm specifically interested in something that would work for 我对某些适合的东西特别感兴趣

  • Azure Data Services Azure数据服务
  • SQL Server SQL服务器
  • sqLite sqLite

...but the theory would apply to any data repository ...但是该理论将适用于任何数据存储库

Has anyone come across a ready built solution or do I have to fix the problem by writing more data access layers than I ever wanted to shake a stick at. 有没有人遇到过现成的解决方案,或者我必须通过编写比我想动摇的更多的数据访问层来解决问题。

Note: I know about ORM's, I want something that removes the requirement to write any of the DAL or stored procs. 注意:我了解ORM,我想要一些东西来消除编写任何DAL或存储的proc的要求。

Take a look at NHibernate, Castle ActiveRecord, SubSonic, LinqToSql, ... 看看NHibernate,Castle ActiveRecord,SubSonic,LinqToSql等...

You say you know about ORMs, but they do pretty much exactly what your question asks for, at least to the extent possible. 您说您了解ORM,但是它们至少在可能的范围内完全满足您的要求。

I know you said that you know about ORM's and don't want them, but could you deal with something where the data access methods you write are written in LINQ ? 我知道您说过您了解ORM,但不希望使用它们,但是您可以处理使用LINQ编写的数据访问方法吗?

I've found that I like writing LINQ statements over SQL statements. 我发现我喜欢在SQL语句上编写LINQ语句。 If you're open to this, I would check out Entity Framework, LINQ to SQL, NHibernate , etc. 如果您愿意这样做,我将签出Entity Framework,LINQ to SQL, NHibernate等。

Edit: If you want to use Azure, check out this link: http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/74a0a57e-d979-48ed-b534-f449bac0f90d 编辑:如果要使用Azure,请查看以下链接: http : //social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/74a0a57e-d979-48ed-b534-f449bac0f90d

This is one of the goals of Salamanca . 这是萨拉曼卡的目标之一。 It is still in early stages though, but we could use a coding hand or two... 虽然它仍处于早期阶段,但是我们可以使用一两手编码。

If you want an existing solution, I suggest you delve into ORMs (as other suggested) possibly associated with code generation tools : 如果需要现有解决方案,建议您深入研究可能与代码生成工具关联的ORM(如其他建议):

Check out this very complete ORMs list . 查看这个非常完整的ORM列表

LINQ to Entities and the Entities framework for .Net are the two best cross-server solutions. LINQ to Entities和.Net的Entities框架是两个最佳的跨服务器解决方案。

More information here: http://msdn.microsoft.com/en-us/library/bb386964.aspx 此处的更多信息: http : //msdn.microsoft.com/zh-cn/library/bb386964.aspx

使用LINQ,实际上可以为您完成所有数据访问任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM