T1.SqlLocalData
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package T1.SqlLocalData --version 1.0.0
NuGet\Install-Package T1.SqlLocalData -Version 1.0.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="T1.SqlLocalData" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add T1.SqlLocalData --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: T1.SqlLocalData, 1.0.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 T1.SqlLocalData as a Cake Addin #addin nuget:?package=T1.SqlLocalData&version=1.0.0 // Install T1.SqlLocalData as a Cake Tool #tool nuget:?package=T1.SqlLocalData&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
First, Create xUnit Test Project, and new SqlLocalDb to create instance
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
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);
}
}
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 | Versions 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.
-
net6.0
- Dapper (>= 2.0.123)
- Microsoft.EntityFrameworkCore (>= 6.0.4)
- Microsoft.EntityFrameworkCore.SqlServer (>= 6.0.4)
- System.Data.SqlClient (>= 4.8.3)
- T1.Standard (>= 1.0.61)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.