Goffo.SqlAccess 1.3.0

dotnet add package Goffo.SqlAccess --version 1.3.0                
NuGet\Install-Package Goffo.SqlAccess -Version 1.3.0                
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="Goffo.SqlAccess" Version="1.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Goffo.SqlAccess --version 1.3.0                
#r "nuget: Goffo.SqlAccess, 1.3.0"                
#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 Goffo.SqlAccess as a Cake Addin
#addin nuget:?package=Goffo.SqlAccess&version=1.3.0

// Install Goffo.SqlAccess as a Cake Tool
#tool nuget:?package=Goffo.SqlAccess&version=1.3.0                

SQL Data Access

SQL Data Access Library that contains Load and Save methods for accessing data from SQL Server. These methods are using Dapper.

Now using Microsoft.Data.SqlClient in v1.0.5

You may need to add "Encrypt = False;" to the end of your Sql Connection string to avoid an error

Code Examples

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using SqlDataAccess;
using Microsoft.Extensions.DependencyInjection;
using OracleDataAccess;


App.Start();

//The Connection String Names in appsettings.json
const string sqlConnName = "SQLDB";
string sql = string.Empty;
IEnumerable<SqlDataModel> sqlData = new List<SqlDataModel>();

sql = @"SELECT Item_Number, ITEM_DESCRIPTION
        FROM dbo.Item";

//setup without Dependency Injection
if (App.Configuration is null)
{
    App.Configuration = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
        .Build();
}

if (App.SqlDataAccess is null)
{
    App.SqlDataAccess = new SqlDataAccess.SqlDataAccess(App.Configuration);
}

sqlData = await App.SqlDataAccess.LoadDataAsync<SqlDataModel, dynamic>(sql: sql,
                                                                       connectionName: sqlConnName,
                                                                       isStoredProcedure: false,
                                                                       sqlParameters: new { },
                                                                       connectionTimeoutSeconds: 0);
//Do something with data....

Console.WriteLine("Total SQL Records = {0}", sqlData.Count());


//With parameters
//========================================
sql = @"SELECT Item_Number, ITEM_DESCRIPTION
        FROM dbo.Item
        WHERE Item_Number = @ItemNumber";

sqlData = await App.SqlDataAccess.LoadDataAsync<SqlDataModel, dynamic>(sql: sql,
                                                                       connectionName: sqlConnName,
                                                                       isStoredProcedure: false,
                                                                       sqlParameters: new { ItemNumber = "44449" });
//Do something with data....

Console.WriteLine("Total SQL Records (with parameter) = {0}", sqlData.Count());

Console.ReadLine();

internal class App
{
    public static Microsoft.Extensions.Configuration.IConfiguration? Configuration { get; set; }
    private static Microsoft.Extensions.Hosting.IHost? _host;

    public static ISqlDataAccess? SqlDataAccess { get; set; }

    public static void Start()
    {
        Configuration = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .Build();

        _host = Host.CreateDefaultBuilder()
            .ConfigureServices(services =>
            {
                services.AddSingleton<ISqlDataAccess, SqlDataAccess.SqlDataAccess>();
            })
            .Build();

        SqlDataAccess = _host.Services.GetRequiredService<ISqlDataAccess>();
    }
}

internal class SqlDataModel
{
    public string? Item_Number { get; set; }
    public string? ITEM_DESCRIPTION { get; set; }
}

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
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.3.0 122 6/21/2024
1.2.0 352 1/17/2024
1.1.0 344 1/3/2024
1.0.0 460 12/7/2023

Updated NuGet packages and using the Dapper QuerySingleOrDefault method