프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / DataBase / EntityModel / MarkusEntities.cs @ ddc223b4

이력 | 보기 | 이력해설 | 다운로드 (2.39 KB)

1

2
namespace Markus.EntityModel
3
{
4
    using System;
5
    using System.Data.Entity;
6
    using System.Data.Entity.Core.EntityClient;
7
    using System.Data.Entity.Infrastructure;
8
    using System.Data.SqlClient;
9

    
10
    public partial class MarkusModel : DbContext
11
    {
12
        private const string providerName = "System.Data.SqlClient";
13
        private const string MarkusMeta = @"res://*/MarkusModel.csdl|res://*/MarkusModel.ssdl|res://*/MarkusModel.msl";
14

    
15
        public MarkusModel(string ConnectionString)
16
            : base(ConnectionStringBuilder(ConnectionString).ToString())
17
        {
18
            this.Database.CommandTimeout = 60;
19
        }
20

    
21
        private static EntityConnectionStringBuilder ConnectionStringBuilder(string ConnectionString)
22
        {
23
            //SqlConnectionStringBuilder _bl = new SqlConnectionStringBuilder(string.Format(Properties.Settings.Default.ProjectCIConnectionString, "DeepView"));
24
            SqlConnectionStringBuilder _bl = new SqlConnectionStringBuilder(ConnectionString);
25
            return EntityConnectionBuilder(_bl, MarkusMeta);
26
        }
27

    
28
        private static EntityConnectionStringBuilder
29
          EntityConnectionBuilder(SqlConnectionStringBuilder SqlStringBuilder, string EntityMetaData)
30
        {
31
            string providerString = SqlStringBuilder.ToString();
32

    
33
            EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
34

    
35
            
36
            entityBuilder.Provider = providerName;
37
            
38
            entityBuilder.ProviderConnectionString = providerString;
39
            entityBuilder.Metadata = EntityMetaData;
40

    
41
            //Console.WriteLine(entityBuilder.ToString());
42
          
43
            using (EntityConnection conn =
44
                new EntityConnection(entityBuilder.ToString()))
45
            {
46
                try
47
                {
48
                    conn.Open();
49
                    //Console.WriteLine("Just testing the connection.");
50
                    conn.Close();
51
                }
52
                catch (Exception ex)
53
                {
54
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
55

    
56
                    if (ex.InnerException != null)
57
                    {
58
                        System.Diagnostics.Debug.WriteLine(ex.InnerException.ToString());
59
                    }
60

    
61
                    throw ex;
62
                }
63
               
64
            }
65

    
66
            return entityBuilder;
67
        }
68

    
69
    }
70
}
클립보드 이미지 추가 (최대 크기: 500 MB)