markus / FinalService / FinalServiceBase / KCOMDataModel / Common / ConnectStringBuilder.cs @ 42d49521
이력 | 보기 | 이력해설 | 다운로드 (3.53 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Data.EntityClient; |
4 |
using System.Data.SqlClient; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
|
8 |
namespace KCOMDataModel.Common |
9 |
{ |
10 |
public class ConnectStringBuilder |
11 |
{ |
12 |
private const string InitialCatalogString = "InitialCatalog"; |
13 |
private const string providerName = "System.Data.SqlClient"; |
14 |
//private const string providerName = "MS.Data.MySqlClient"; //MYSQL 일때 사용 |
15 |
private const string DeepViewMeta = @"res://*/DataModel.KCOM_Model.csdl|res://*/DataModel.KCOM_Model.ssdl|res://*/DataModel.KCOM_Model.msl"; |
16 |
private const string CIMeta = @"res://*/DataModel.CIModel.csdl|res://*/DataModel.CIModel.ssdl|res://*/DataModel.CIModel.msl"; |
17 |
|
18 |
|
19 |
public static EntityConnectionStringBuilder KCOMConnectionString() |
20 |
{ |
21 |
SqlConnectionStringBuilder _bl = new SqlConnectionStringBuilder(string.Format(CommonLib.Common.GetConnectionString(), "markus")); |
22 |
return EntityConnectionStringBuilder(_bl, DeepViewMeta); |
23 |
} |
24 |
public static EntityConnectionStringBuilder ProjectCIConnectString(string ProjectNo) |
25 |
{ |
26 |
return CIConnectionStringBuilder(CommonLib.Common.GetConnectionString(), ProjectNo, CIMeta); |
27 |
} |
28 |
|
29 |
private static EntityConnectionStringBuilder CIConnectionStringBuilder(string adoConnectionString, string ProjectNo, string Metadata) |
30 |
{ |
31 |
try |
32 |
{ |
33 |
SqlConnectionStringBuilder bl = new SqlConnectionStringBuilder(string.Format(CommonLib.Common.GetConnectionString(), "markus")); |
34 |
|
35 |
using (DataModel.KCOMEntities entity |
36 |
= new DataModel.KCOMEntities(EntityConnectionStringBuilder(bl, DeepViewMeta).ToString())) |
37 |
{ |
38 |
var _catalog = entity.PROPERTIES.Where(property => property.TYPE == InitialCatalogString |
39 |
/*&& property.PROPERTY == ProjectNo*/); |
40 |
EntityConnectionStringBuilder builder = null; |
41 |
if (_catalog.Count() > 0) |
42 |
{ |
43 |
string _ConnectionString = string.Format(adoConnectionString, _catalog.First().VALUE); |
44 |
SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(_ConnectionString); |
45 |
|
46 |
builder = ConnectStringBuilder.EntityConnectionStringBuilder(sqlBuilder, Metadata); |
47 |
} |
48 |
|
49 |
return builder; |
50 |
} |
51 |
} |
52 |
catch (Exception ex) |
53 |
{ |
54 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
55 |
} |
56 |
|
57 |
return null; |
58 |
} |
59 |
|
60 |
private static EntityConnectionStringBuilder EntityConnectionStringBuilder(SqlConnectionStringBuilder SqlStringBuilder, string EntityMetaData) |
61 |
{ |
62 |
string providerString = SqlStringBuilder.ToString(); |
63 |
|
64 |
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(); |
65 |
|
66 |
entityBuilder.Provider = providerName; |
67 |
entityBuilder.ProviderConnectionString = providerString; |
68 |
entityBuilder.Metadata = EntityMetaData; |
69 |
//Console.WriteLine(entityBuilder.ToString()); |
70 |
|
71 |
//using (EntityConnection conn = |
72 |
// new EntityConnection(entityBuilder.ToString())) |
73 |
//{ |
74 |
// conn.Open(); |
75 |
// Console.WriteLine("Just testing the connection."); |
76 |
// conn.Close(); |
77 |
//} |
78 |
|
79 |
return entityBuilder; |
80 |
} |
81 |
} |
82 |
} |