using System;
using System.Data.Entity.Core.EntityClient;
using System.Data.SQLite;
namespace Application.Ringtoets.Storage
{
///
/// This class builds a connection string to an SQLite database file.
///
public static class SqLiteConnectionStringBuilder
{
///
/// Constructs a connection string to connect the Entity Framework to .
///
/// Location of the storage file.
/// A new connection string.
/// Thrown when is null.
public static string BuildSqLiteEntityConnectionString(string filePath)
{
return new EntityConnectionStringBuilder
{
Metadata = string.Format(@"res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl", "DbContext.RingtoetsEntities"),
Provider = @"System.Data.SQLite.EF6",
ProviderConnectionString = BuildSqLiteConnectionString(filePath)
}.ConnectionString;
}
///
/// Constructs a connection string to connect to .
///
/// Location of the storage file.
/// A new connection string.
/// Thrown when is null.
public static string BuildSqLiteConnectionString(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new ArgumentNullException("filePath", "Cannot create a connection string without the path to the file to connect to.");
}
return new SQLiteConnectionStringBuilder
{
FailIfMissing = true,
DataSource = filePath,
ReadOnly = false,
ForeignKeys = true,
Version = 3,
Pooling = true
}.ConnectionString;
}
}
}