Author - StudySection Post Views - 408 views
Data Gateway

Table Data Gateway Pattern in C#

It is an object that acts as a Gateway to a database table. It handles all the rows in the table.
Gateway: It is an object that encapsulates access to an external system or resource.

It holds all the SQL for accessing a single table or view:

  • Selects, inserts, updates, and deletes.
  • It is a method for all interactions with the database.
  • Providing a gateway class for each database table and mixing SQL in application logic can cause several problems and separates the SQL queries from code.
  • It has a simple interface, usually consisting of several find methods to get data from the database and update, insert, and delete methods.
  • The maps are the input parameters into a SQL call and execute the SQL against a database connection. It is usually stateless, as its role is to push data back and forth.

The pattern separates the SQL queries from the source code.

  • It is probably the database interface pattern to use, as it maps so nicely onto a database table or record type.
  • I use it least with Domain Model because Data Mapper gives better isolation between the Domain Model and a database.
  • It has one for each table in the database.
  • It is a single Table Data Gateway that handles all methods for all tables.
  • To encapsulate database access and the same interface can work both for using SQL to manipulate the database and for using stored procedures.

Sample Code:

Create a Model Class:
public class Employee{
private int id;
private string emp_name;
private string dept_name;
private string gender;
private int age;
private float salary;

Step 2: Create an EmployeeGatway class: It holds all the SQL for accessing a single table or view: select, inserts, updates, and deletes.
public class EmployeeGateWay{
public RecordSet find(int id)
// find employee record by id.
public RecordSet findByName()
// find employee records by Name.
public void update(sting emp_name,string dept_name,int age)
//update employee entity.
public void insert(string emp_name,string dept_name,string gender,int age,float salary)
//insert employee entity
public void delete(int id)
//Delete employee records by id from the database.

English is a commonly used language in almost all fields today. Having a certification in the English language can enhance your career aspects. StudySection offers both basic level and advanced level English Certification Exams to test and certify the English language skills.

Leave a Reply

Your email address will not be published. Required fields are marked * cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri