ttmind

Main Navigation

ttmind
  • jim-jams
  • Tech
  • Positive
Login

Login

Facebook Google

OR

Remember me Forgot password?

Don't have account? Signup here.

Sort by Categorys

.Net

PHP

Java

JavaScript

Database

Server

Client Side

Tools

Artificial Intelligence

Cloud

Hybrid Development

Event

Smart City

Education

Security

Scrum

Digital Marketing

APP Development

Business

Internet

Simulation

Art

Network

Microservices

Architecture

Technology

Leadership

    Top Articles

  • How Does Social Media Bring People Together?
    TTMind Author
  • How to read appSettings JSON from Class Library in ASP.NET Core
    Anil Shrestha
  • Printing Support In Asp.Net Core
    TTMind Author
  • HOW TO EXTRACT TEXT FROM IMAGE USING JAVASCRIPT (OCR with Tesseract.js)?
    Prakash Pokhrel
  • Images Upload REST API using ASP.NET Core
    Prakash Pokhrel
  • Related Topic

  • How to read appSettings JSON from Class Library in ASP.NET Core
  • Printing Support In Asp.Net Core
  • Images Upload REST API using ASP.NET Core
  • How to use IActionFilter, IAsyncActionFilter in ASP.NET Core MVC?
  • ASP.NET CORE - Blazor CRUD operation using ADO.NET
  • Tech
  • About Us
  • Contact Us
  • TechHelp
  • PositiveHelp
  • Jim-Jams Help
  • Terms & Conditions

© Copyright ttmind.com

Main Content

How to use ADO.NET in .NET Core 2.x for Performance Critical Applications

.Net ADO.NET about 7 years ago || 8/29/2018 || 6.8 K View

  • Hide

If you working with .NET framework from a long time then you must have used SQL Helper or a similar library to work with SQL Server or if you working with some performance-critical applications and want to directly work with ADO.NET then you can use your ADO.NET with this SQL helper. I tried to convert it so that it can work with ADO.NET as well as achieve async feature as well in .NET Core 2.x.

So this SQL Helper Library basically has two main class file, that can be used easily for DML operations of SQL Database. A one just has to create an object and start using it.
The two class are,

  • SQLHandler
  • SQLHandlerAsync

And helper classes are

  • DataSourceHelper
  • Null

So this two SQLHandler and SQLHandlerAsync classes have pure ADO.NET methods like,

  • ExecuteNonQuery and  ExecuteNonQueryAsync,
  • ExecuteAsDataSet and ExecuteAsDataSetAsync,
  • ExecuteAsDataReader and ExecuteAsDataReaderAsync,
  • ExecuteAsObject and ExecuteAsObjectAsync,
  • ExecuteAsList and ExecuteAsListAsync

Which can be used directly and can provide the best performance as required and handled from SQL Stored Procedures.

This SQLHandler and SQLHandlerAsync use NuGetPackage System.Data.SqlClient to support pure ADO.NET features like DataTable and DataSet etc.

Examples
How to use SQLHandlerAsync for ExecuteNonQueryAsync

public async Task<int> AddProject(ProjectInfo objInfo)
{
    List<KeyValuePair<string, object>> Param = new List<KeyValuePair<string, object>>();
    Param.Add(new KeyValuePair<string, object>("@ProjectName", objInfo.ProjectName));
    Param.Add(new KeyValuePair<string, object>("@ProjectCode", objInfo.ProjectCode));
    string strSpName = "usp_AddProject";
    SQLHandlerAsync sqlHAsy = new SQLHandlerAsync();
    return await sqlHAsy.ExecuteNonQueryAsync(strSpName, Param);
}

How to use SQLHandlerAsync for ExecuteAsObjectAsync

public async Task<ProjectInfo> GetProject(ProjectInfo objInfo)
{
    List<KeyValuePair<string, object>> Param = new List<KeyValuePair<string, object>>();
    Param.Add(new KeyValuePair<string, object>("@ProjectID", objInfo.ProjectID));            
    string strSpName = "usp_GetProject";
    SQLHandlerAsync sqlHAsy = new SQLHandlerAsync();
    //List<ProjectInfo> objList = await sqlHAsy.ExecuteAsListAsync<ProjectInfo>(strSpName, Param);
    return await sqlHAsy.ExecuteAsObjectAsync<ProjectInfo>(strSpName, Param);
}

How to use SQLHandlerAsync for ExecuteAsListAsync

public async Task<List<ProjectInfo>> GetProjectList()
{    
    string strSpName = "usp_GetProjectList";
    SQLHandlerAsync sqlHAsy = new SQLHandlerAsync();    
    return await sqlHAsy.ExecuteAsListAsync<ProjectInfo>(strSpName);
}


A source project is in Github a link is SQLHelper With ADO.NET SQL Helper

This repository has 3 projects, but SQL Helper is the main the rest two projects are just to test and shown as an example to use it.

A SQLHandler and SQLHandlerAsync both are partial classes so if required it can also accept more options too.

As these classes are for MS SQL only, it would be great if some friends can extend it for the mysql and mongodb etc too.

Hope it will help someone who need to work with ADO.NET in .NET Core.

  • 2
  • 0
  • 0
    • Facebook
    • Twitter
    • Google +
    • LinkedIn

About author

Alok Pandey

Alok Pandey

Love to share what I know.

Reset Your Password
Enter your email address that you used to register. We'll send you an email with your username and a link to reset your password.

Quick Survey