Data access level

how can we create a common data access layer that can be used by any asp.net application using a different data provider or web service?

Can I create a data access layer for an application using webservice?

+3
source share
6 answers

You can view the repository template. A repository is a facade that represents stored objects, as if they were in a collection in memory. Whichever provider you choose to receive the data is hidden behind the repository interface.

IRepository with LINQ to SQL

Code Design Tutorial

Sample Fredrick Calcet

+5
source

You have many options! :-)

, (DAL) asp.net -. .

, , , DAL , / .

:

  • Linq-to-SQL , SQL Server Linq-to-SQL.
  • ( "", "EntityRepository", , EntityReposity.GetByID(int id) EntityRepository.GetByForeignKey( fk)
  • (NHibernate, ADO.NET)
  • webservice

- .

. - , :

+2

www.asp.net:

DataAccess

+1

, . , , , , 3/4.

, , - . , , , CMS. , IQueryable, , # POCO ( CLR).

public interface ICMSRepository {
    IQueryable<ContentSection> GetContentSections();
    void SaveContentSection(ContentSection obj);
}

, LINQ to SQL, POCO . , IQueryable, , . :

public static IQueryable<ContentSection> WithID(this IQueryable<ContentSection> qry, int ID) {
    return from c in qry select c;
}

//Allow you to chain repository and filter to delay SQL execution
ICMSRepository _rep = new SqlCMSRepository();
var sec = _rep.GetContentSections().WithID(1).SingleDefault();

Interface - , .

, ASP.Net, . , , singleton, (XML, , SQL, MySql ..). singleton . .

.

0

IRepository of T - . GetAll, GetByID, Insert, Delete Submit.
- Repository / .
, IQueriable GetAll, , IRepository, IQueriable. . .

0

:

IDbConnection IDbCommand IDbDataAdapter IDataReader

0

Source: https://habr.com/ru/post/1705316/


All Articles