简体   繁体   中英

Use repository without Entity Framework

I try to figure out how to implement the repository pattern WITHOUT Entity Framework. I need to use the ADO.NET (disconnected) implementation,(withot DbContext ). I know if it is possible.

I have one interface of Repository like it:

public interface IRepository<T>
{
    void Add(T newEntity);
    void Remove(T Entity);
    void Update(T Entity);
    IQueryable<T> GetAll();
    T Get(object key);
    void SaveChanges();                
}

So, I just need to know how use it with ADO.NET connection and Mapper or other thing.

Your question is about the repository pattern, however your sample looks more like writing a custom linq provider.

This is actually rather complex thing, and what i think you actually need is to really use the repository pattern, where you have methods like GetCar(int Id) that you then implement specifically using what ever framwork you want.

The diffrence is that with a linq provider like EF, you're exposing the ability for callers to write write any query they want. However, technically this breaks the repository pattern. The idea with the Repo pattern is to contain all the queries in a single class that then expose methods for doing only what the application needs. This way you don't get queries all over your code, and you can implement only the operations your application needs.

In other words, EF is not really an example of the repository pattern, it's a way to talk to the database and create classes that represent the entities in the database. Typically you'd use EF or something similar inside your repository and possibly expose the actual entity types for the outside to use.

Now, writing a custom linq provider is still interesting and if you want to do it, check out this series: http://www.jacopretorius.net/2010/01/implementing-a-custom-linq-provider.html

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