-
-
Notifications
You must be signed in to change notification settings - Fork 44
Migrating to MartinCostello.SqlLocalDb from System.Data.SqlLocalDb
Martin Costello edited this page Jan 18, 2022
·
4 revisions
This document explains some of the steps required to migrate from
System.Data.SqlLocalDb 1.x.x to MartinCostello.SqlLocalDb 2.0.0 and
later. It is not exhaustive as use-cases may differ, but illustrates equivalent
namespace and type names, as well as equivalents for certain tasks.
- Remove references(s) to the
System.Data.SqlLocalDbNuGet package. - Add reference(s) to the
MartinCostello.SqlLocalDbNuGet package. - Change uses of the
System.Data.SqlLocalDbnamespace toMartinCostello.SqlLocalDb. - Change usage of
SqlLocalDbApiWrapperforSqlLocalDbApi. - Remove any application settings used by
System.Data.SqlLocalDbto using theSqlLocalDbOptionsclass in code instead (see Configuration). - Remove any references to the static
SqlLocalDbApiclass and use instance-based methods onSqlLocalDbApi/ISqlLocalDbApiand/orISqlLocalDbInstanceManager/SqlLocalDbInstanceManagerinstead. - Change any usage of
ISqlLocalDbInstancetoISqlLocalDbInstanceInfo. - Change any usage of static methods on the
TemporarySqlLocalDbInstanceclass to use theCreateTemporaryInstance()extension method on theISqlLocalDbApiinterface instead. - For dependency injection in .NET Core applications, you can use the
AddSqlLocalDB()method withIServiceCollectionto register theISqlLocalDbApiandSqlLocalDbOptionstypes.
using var localDB = new SqlLocalDbApi();
if (!localDB.IsLocalDBInstalled())
{
// Do something if SQL Server LocalDB is not installed
}using var localDB = new SqlLocalDbApi();
var instances = localDB.GetInstances();
foreach (ISqlLocalDbInstanceInfo instanceInfo in instances)
{
// Do something with the instances
}using var localDB = new SqlLocalDbApi();
if (localDB.InstanceExists("MyInstance"))
{
// Do something if the instance exists
}using var localDB = new SqlLocalDbApi();
ISqlLocalDbInstanceInfo instance = localDB.CreateInstance("MyInstance");
// Do something with the instanceusing var localDB = new SqlLocalDbApi();
var instance = localDB.GetInstanceInfo("MyInstance");
var manager = new SqlLocalDbInstanceManager(instance, localDB);
manager.Start();
using SqlConnection connection = manager.CreateConnection();
await connection.OpenAsync();
try
{
// Do something with the SQL connection
}
finally
{
await connection.CloseAsync();
}