blob: 3508e113798c2af2cdf6006a37860714b65cc019 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Settings;
namespace Tango.DAL.Remote.DB
{
/// <summary>
/// Represents an SQL Server database context.
/// </summary>
/// <seealso cref="System.Data.Entity.DbContext" />
public partial class RemoteDB : DbContext
{
/// <summary>
/// Initializes a new instance of the <see cref="RemoteDB"/> class.
/// </summary>
/// <param name="path">The server file path.</param>
/// <param name="isFile">if set to <c>true</c> will try to connect to an .mdf file.</param>
public RemoteDB(String path, bool isFile) : base(ComposeConnectionString(path, isFile))
{
}
/// <summary>
/// Composes the connection string.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="isFile">if set to <c>true</c> [is file].</param>
/// <returns></returns>
private static String ComposeConnectionString(String source, bool isFile)
{
if (!isFile)
{
return String.Format("metadata=res://*/DB.RemoteADO.csdl|res://*/DB.RemoteADO.ssdl|res://*/DB.RemoteADO.msl;provider=System.Data.SqlClient;provider connection string=\"data source={0};initial catalog=Tango;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework\"", source);
}
else
{
return null;
}
}
/// <summary>
/// Creates a default remote database context by the address specified in <see cref="SettingsManager.Default.DataBase.SQLServerAddress"/>.
/// </summary>
/// <returns></returns>
public static RemoteDB CreateDefault()
{
return new RemoteDB(SettingsManager.Default.GetOrCreate<CoreSettings>().SQLServerAddress, false);
}
}
}
|