Questions tagged [data-access-layer]

Data access layer is a layer of a computer program which provides simplified access to data stored in persistent storage of some kind, such as an entity-relational database.

A data access layer (DAL) in computer software, is a layer of a computer program which provides simplified access to data stored in persistent storage of some kind, such as an entity-relational database.

For example, the DAL might return a reference to an object (in terms of object-oriented programming) complete with its attributes instead of a row of fields from a database table. This allows the client (or user) modules to be created with a higher level of abstraction. This kind of model could be implemented by creating a class of data access methods that directly reference a corresponding set of database stored procedures. Another implementation could potentially retrieve or write records to or from a file system. The DAL hides this complexity of the underlying data store from the external world.

For example, instead of using commands such as insert, delete, and update to access a specific table in a database, a class and a few stored procedures could be created in the database. The procedures would be called from a method inside the class, which would return an object containing the requested values. Or, the insert, delete and update commands could be executed within simple functions like registeruser or loginuser stored within the data access layer.

Also, business logic methods from an application can be mapped to the Data Access Layer. So, for example, instead of making a query into a database to fetch all users from several tables the application can call a single method from a DAL which abstracts those database calls.

1287 questions
20
votes
4 answers

Why is DataTable faster than DataReader

So we have had a heated debate at work as to which DataAccess route to take: DataTable or DataReader. DISCLAIMER I am on the DataReader side and these results have shaken my world. We ended up writing some benchmarks to test the speed differences.…
Shai Cohen
  • 6,074
  • 4
  • 31
  • 54
18
votes
2 answers

Difference between Data Access Layer and Model in MVC

I have implemented what I thought was a pretty decent representation of MVC in several web applications but since having joined crackoverflow, I'm finding that perhaps my initial definitions were a bit simplistic and thus I'd really like some…
Noah Goodrich
  • 24,875
  • 14
  • 66
  • 96
17
votes
7 answers

Do you allow the Web Tier to access the DAL directly?

I'm interested in perceived "best practice", tempered with a little dose of reality here. In a web application, do you allow your web tier to directly access the DAL, or should it go through a BLL first? I'm talking specifically of scenarios where…
Marty Pitt
  • 28,822
  • 36
  • 122
  • 195
17
votes
7 answers

What are the disadvantages of Typed DataSets

I come from a world that favors building your own rather than rely on libraries and frameworks built by others. After escaping this world I have found the joy, and ease, of using such tools as Typed DataSets within Visual Studio. So besides the loss…
Craig Tyler
  • 470
  • 6
  • 9
17
votes
5 answers

Execute stored procedure w/parameters in Dapper

I'm using Dapper (thanks Sam, great project.) a micro ORM with a DAL and by some reason I'm not able to execute stored procedures with input parameters. In a example service I've the following code: public void GetSomething(int somethingId) { …
antao
  • 767
  • 1
  • 9
  • 24
17
votes
4 answers

What is the best practice for multiple "Include"-s in Entity Framework?

Let's say we have four entities in data model: Categories, Books, Authors and BookPages. Also assume Categories-Books, Books-Authors and Books-BookPages relationships are one-to-many. If a category entity instance is retrieved from database -…
16
votes
4 answers

Best "pattern" for Data Access Layer to Business Object

I'm trying to figure out the cleanest way to do this. Currently I have a customer object: public class Customer { public int Id {get;set;} public string name {get;set;} public List emailCollection {get;set} public Customer(int…
Dave Baghdanov
  • 2,288
  • 5
  • 24
  • 35
16
votes
3 answers

How do I use Dapper to get the return value of stored proc?

I'm using Dapper in asp.net mvc 4 project .net f/w 4.6.1 using sql server 2016 express I have a stored proc which deletes from 2 tables which should be…
Hamza Ahmed
  • 1,571
  • 4
  • 18
  • 35
15
votes
2 answers

django models = business logic + data access? Or data access layer should be separated out from django model?

In Django, the suggested software architecture is to put all business logic and data access in models. But, some colleagues have suggested that the data access layer should be separate from the business logic (business service layer). Their…
15
votes
5 answers

JPA why use createNamedQuery

I'm in the processes of changing my DAO layer from using Hibernate API to using a pure JPA API implementation. It looks like the recommended method is to use the createNamedQuery from the entity manager. The named queries are stored in annotations…
Ruggs
  • 1,600
  • 2
  • 16
  • 25
15
votes
2 answers

I'm having problems understanding IQueryable

So I'm trying to understand IQueryable. A tutorial I'm reading suggests using it but not really sure why. The code simply returns some values using LINQ to SQL. I've done this plenty of times in the past, but not using IQueryable Why use it…
ItsPronounced
  • 5,475
  • 13
  • 47
  • 86
15
votes
3 answers

In separate data access & business logic layer, can I use Entity framework classes in business layer?

In separate data access & business logic layer, can I use Entity framework classes in business layer? EDIT: I don't think I will need to swap out the data access layer from my business logic in the future (i.e. will be SQL Server), however I will…
Greg
  • 34,042
  • 79
  • 253
  • 454
14
votes
4 answers

Should I Unit Test Data Access Layer? Is this a good practice and how to do it?

If I'm having Data Access Layer (nHibernate) for example a class called UserProvider and a Business Logic class UserBl, should I both test their methods SaveUser or GetUserById, or any other public method in DA layer which is called from BL layer.…
nemke
  • 2,440
  • 3
  • 37
  • 57
14
votes
4 answers

What are the pros/cons of choosing between static and instance data access classes in a web app?

I've read several other questions on this topic (here, here, and here), but have yet to see a great answer. I've developed my fair share of data access layers before and personally prefer to use instance classes instead of static classes. However,…
Kevin Babcock
  • 10,187
  • 19
  • 69
  • 89
14
votes
2 answers

best practices for "data layer" in android client apps

Here is one design/ best practices question.. I'm new to android development, and basically new to web/mobile solutions. So, my question is - what are best practices when organizing structure of android application that get data from the remote…
1 2
3
85 86