-
-
Notifications
You must be signed in to change notification settings - Fork 43
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.SqlLocalDb
NuGet package. - Add reference(s) to the
MartinCostello.SqlLocalDb
NuGet package. - Change uses of the
System.Data.SqlLocalDb
namespace toMartinCostello.SqlLocalDb
. - Change usage of
SqlLocalDbApiWrapper
forSqlLocalDbApi
. - Remove any application settings used by
System.Data.SqlLocalDb
to using theSqlLocalDbOptions
class in code instead (see Configuration). - Remove any references to the static
SqlLocalDbApi
class and use instance-based methods onSqlLocalDbApi
/ISqlLocalDbApi
and/orISqlLocalDbInstanceManager
/SqlLocalDbInstanceManager
instead. - Change any usage of
ISqlLocalDbInstance
toISqlLocalDbInstanceInfo
. - Change any usage of static methods on the
TemporarySqlLocalDbInstance
class to use theCreateTemporaryInstance()
extension method on theISqlLocalDbApi
interface instead. - For dependency injection in .NET Core applications, you can use the
AddSqlLocalDB()
method withIServiceCollection
to register theISqlLocalDbApi
andSqlLocalDbOptions
types.
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 instance
using 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();
}