TA.DataAccess.SqlServer 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package TA.DataAccess.SqlServer --version 1.0.2
NuGet\Install-Package TA.DataAccess.SqlServer -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TA.DataAccess.SqlServer" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TA.DataAccess.SqlServer --version 1.0.2
#r "nuget: TA.DataAccess.SqlServer, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TA.DataAccess.SqlServer as a Cake Addin
#addin nuget:?package=TA.DataAccess.SqlServer&version=1.0.2

// Install TA.DataAccess.SqlServer as a Cake Tool
#tool nuget:?package=TA.DataAccess.SqlServer&version=1.0.2

TA.DataAccess.SqlServer

TA.DataAccess.SqlServer is a comprehensive .NET library designed to simplify database operations with SQL Server. It provides a range of methods to execute queries, retrieve data, and perform CRUD operations using strongly-typed models.

Features

  • Execute non-query commands
  • Execute multiple non-query commands within a transaction
  • Retrieve data as DataTable
  • Retrieve data as a list of strongly-typed models
  • Insert, update, and delete models
  • Use custom attributes to exclude properties from CRUD operations

Installation

You can install the package via NuGet Package Manager:

dotnet add package TA.DataAccess.SqlServer

Usage

Configuration

Ensure your appsettings.json has the connection string:

{
  "ConnectionStrings": {
    "DefaultConnection": "Your Connection String Here"
  }
}

Dependency Injection

Register the SqlServerHelper in your Startup.cs or Program.cs:

public void ConfigureServices(IServiceCollection services)
{
    services.AddSingleton<ISqlServerHelper, SqlServerHelper>();  
}

Example Usage

using Microsoft.Extensions.Configuration;
using TA.DataAccess.SqlServer;
using System.Collections.Generic;
using System.Data;

public class MyService
{
    private readonly ISqlServerHelper _sqlServerHelper;

    public MyService(ISqlServerHelper sqlServerHelper)
    {
        _sqlServerHelper = sqlServerHelper;
    }

    public void ExecuteSampleQueries()
    {
        // Execute a non-query command
        _sqlServerHelper.ExecuteNonQuery("INSERT INTO MyTable (Column1) VALUES (@Value)", new SqlParameter[] { new SqlParameter("@Value", "SampleValue") });

        // Execute a query and get results as DataTable
        DataTable dt = _sqlServerHelper.Select("SELECT * FROM MyTable");

        // Execute a query and get results as a list of strongly-typed models
        List<MyModel> models = _sqlServerHelper.Select<MyModel>("SELECT * FROM MyTable");

        // Insert a model
        MyModel model = new MyModel { Column1 = "Value1", Column2 = "Value2" };
        _sqlServerHelper.InsertModel(model, "MyTable");

        // Insert multiple models
        List<MyModel> modelList = new List<MyModel> { model, model };
        _sqlServerHelper.InsertModels(modelList, "MyTable");
    }
}


public class MyModel
{
    public int Id { get; set; }
    public string Column1 { get; set; }
    public string Column2 { get; set; }
}

Custom Attributes

You can use the NoCrudAttribute to exclude properties from CRUD operations:

public class MyModel
{
    public int Id { get; set; }
    
    [NoCrud]
    public string ExcludedColumn { get; set; }
    
    public string Column1 { get; set; }
    public string Column2 { get; set; }
}

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 76 6/10/2024
1.0.5 57 6/7/2024
1.0.4 68 6/7/2024
1.0.3 72 6/6/2024
1.0.2 75 6/5/2024
1.0.1 75 6/5/2024
1.0.0 79 6/5/2024

Bug Fixed and some basic info added