简体   繁体   中英

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.

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
  • SQL Server
  • 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.

Take a look at 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.

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 ?

I've found that I like writing LINQ statements over SQL statements. If you're open to this, I would check out Entity Framework, LINQ to SQL, NHibernate , etc.

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

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 :

Check out this very complete ORMs list .

LINQ to Entities and the Entities framework for .Net are the two best cross-server solutions.

More information here: http://msdn.microsoft.com/en-us/library/bb386964.aspx

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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