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 SqLiteStorageConnection { /// /// 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) { if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentNullException(); } return new EntityConnectionStringBuilder { Metadata = string.Format(@"res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl", "DbContext.RingtoetsEntities"), Provider = @"System.Data.SQLite.EF6", ProviderConnectionString = new SQLiteConnectionStringBuilder { FailIfMissing = true, DataSource = filePath, ReadOnly = false, ForeignKeys = true, Version = 3, Pooling = true }.ConnectionString }.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(); } return new SQLiteConnectionStringBuilder { FailIfMissing = true, DataSource = filePath, ReadOnly = false, ForeignKeys = true, Version = 3, Pooling = true }.ConnectionString; } } }