markus / KCOMDataModel / Common / ConnectStringBuilder.cs @ master
이력 | 보기 | 이력해설 | 다운로드 (3.53 KB)
1 | 787a4489 | KangIngu | 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 | 5928384e | djkim | SqlConnectionStringBuilder _bl = new SqlConnectionStringBuilder(string.Format(CommonLib.Common.GetConnectionString(), "markus")); |
22 | 787a4489 | KangIngu | return EntityConnectionStringBuilder(_bl, DeepViewMeta); |
23 | } |
||
24 | public static EntityConnectionStringBuilder ProjectCIConnectString(string ProjectNo) |
||
25 | { |
||
26 | 84c48033 | djkim | return CIConnectionStringBuilder(CommonLib.Common.GetConnectionString(), ProjectNo, CIMeta); |
27 | 787a4489 | KangIngu | } |
28 | |||
29 | private static EntityConnectionStringBuilder CIConnectionStringBuilder(string adoConnectionString, string ProjectNo, string Metadata) |
||
30 | { |
||
31 | try |
||
32 | { |
||
33 | 84c48033 | djkim | SqlConnectionStringBuilder bl = new SqlConnectionStringBuilder(string.Format(CommonLib.Common.GetConnectionString(), "markus")); |
34 | 787a4489 | KangIngu | |
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 | c247e6b4 | humkyung | /*&& property.PROPERTY == ProjectNo*/); |
40 | 787a4489 | KangIngu | 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 | 84c48033 | djkim | //Console.WriteLine(entityBuilder.ToString()); |
70 | 787a4489 | KangIngu | |
71 | 84c48033 | djkim | //using (EntityConnection conn = |
72 | // new EntityConnection(entityBuilder.ToString())) |
||
73 | //{ |
||
74 | // conn.Open(); |
||
75 | // Console.WriteLine("Just testing the connection."); |
||
76 | // conn.Close(); |
||
77 | //} |
||
78 | 787a4489 | KangIngu | |
79 | return entityBuilder; |
||
80 | } |
||
81 | } |
||
82 | } |