T1.SqlLocalData 1.0.1

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

// Install T1.SqlLocalData as a Cake Tool
#tool nuget:?package=T1.SqlLocalData&version=1.0.1                

First, Create xUnit or other test project, and new SqlLocalDb to create instance

using T1.SqlLocalData;

public class SqlLocalDbTest : IDisposable
{
    private string _instanceName = "local_db_instance";
    private string _databaseName = "Northwind";
    private readonly SqlLocalDb _localDb = new SqlLocalDb(@"D:\Demo");

    public SqlLocalDbTest()
    {
        _localDb.EnsureInstanceCreated(_instanceName);
        _localDb.ForceDropDatabase(_instanceName, _databaseName);
        _localDb.DeleteDatabaseFile(_databaseName);
        _localDb.CreateDatabase(_instanceName, _databaseName);
    }
}
  • EnsureInstanceCreated: Ensure local_db_instance instance created
  • ForceDropDatabase: Force delete exists database
  • DeleteDatabaseFile: Delete mdf ldf files
  • CreateDatabase: Create database

<br/> <br/>

The SqlLocalDb.exe default installed location is "C:\Program Files\Microsoft SQL Server\150\Tools\Binn". If you installed it in other location, then you can change default location by SetInstalledLocation method.

_localDb.SetInstalledLocation("D:\\OtherLocation\\Binn");

<br/>

Setting connectionString to local_db_instance

public class MyDbContext : DbContext
{
	string _connectionString = "Server=(localdb)\\local_db_instance;Integrated security=SSPI;database=Northwind;";
	
	public DbSet<CustomerEntity> Customers { get; set; }
	
	protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
	{
		optionsBuilder.UseSqlServer(_connectionString);
	}
}

<br/> Finish, you can use local_db_instance to test your code in Integrated Database Test Project.

[Fact]
public void execute_store_procedure()
{
    var myDb = new MyDbContext();
    myDb.Database.ExecuteSqlRaw(@"CREATE TABLE customer (id INT PRIMARY KEY, name VARCHAR(50))");
    myDb.Database.ExecuteSqlRaw(@"INSERT customer(id,name) VALUES (1,'Flash'),(3,'Jack'),(4,'Mary')");
    myDb.Database.ExecuteSqlRaw(@"CREATE PROC MyGetCustomer 
        @id INT AS 
        BEGIN 
            SET NOCOUNT ON; 
            select name from customer 
            WHERE id=@id 
        END");

    var customer = myDb.QuerySqlRaw<CustomerEntity>("EXEC MyGetCustomer @id", new
    {
        id = 3
    }).First();

    Assert.Equal("Jack",customer.Name);
}
Product Compatible and additional computed target framework versions.
.NET 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 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 was computed.  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. 
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.1 501 6/5/2022
1.0.0 477 5/29/2022

add installedLocation