프로젝트

일반

사용자정보

개정판 fdecb3be

IDfdecb3bea05ccd11da9594690363c35b706ae4a5
상위 2327ae11
하위 40849448

유성호이(가) 약 2년 전에 추가함

issue #0000
sqlite 추가진행

Change-Id: I20edcd51de288849693bbe85dfdf9417f8741cc8

차이점 보기:

ID2.Manager/ID2.Manager.Dapper/DatabaseEnums.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace ID2.Manager.Dapper
8
{
9
    public enum DatabaseType
10
    {
11
        MSSQL,
12
        SQLITE
13
    }
14
}
ID2.Manager/ID2.Manager.Dapper/ID2.Manager.Dapper.csproj
61 61
    <Reference Include="System.Xml" />
62 62
  </ItemGroup>
63 63
  <ItemGroup>
64
    <Compile Include="DatabaseEnums.cs" />
64 65
    <Compile Include="Entities\DocPage.cs" />
65 66
    <Compile Include="Entities\DOCUMENTITEM.cs" />
66 67
    <Compile Include="IBaseRepository.cs" />
ID2.Manager/ID2.Manager.Dapper/Repository/BaseRepository.cs
7 7
using System.Data;
8 8
using System.Data.SqlClient;
9 9
using System.ComponentModel.DataAnnotations.Schema;
10
using System.Data.SQLite;
10 11

  
11 12
using Dapper;
12 13

  
......
14 15
{
15 16
    public abstract class BaseRepository : IBaseRepository
16 17
    {
17
        protected readonly IDbConnection _DbConnection;//readonly 삭제해야하는지 확인
18
        protected readonly IDbConnection _DbConnection;
18 19
        protected IDbTransaction _DbTransaction = null;
19 20

  
20
        public SqlConnection DBConnection(string connectionStr)
21
        protected BaseRepository(string connectionStr)
21 22
        {
22
            return new SqlConnection(connectionStr);
23
            this._DbConnection = this.DBConnection(connectionStr);
23 24
        }
24 25

  
25
        public IDbTransaction BeginTransaction()
26
        protected BaseRepository(string connectionStr, DatabaseType dbType)
26 27
        {
27
            if (this._DbConnection.State != ConnectionState.Open)
28
            switch (dbType)
28 29
            {
29
                this._DbConnection.Open();
30
                case DatabaseType.SQLITE:
31
                    this._DbConnection = this.SQLiteDBConnection(connectionStr);
32
                    break;
33
                case DatabaseType.MSSQL:
34
                default:
35
                    this._DbConnection = this.DBConnection(connectionStr);
36
                    break;
30 37
            }
31

  
32
            return this._DbConnection.BeginTransaction();
33 38
        }
34 39

  
35
        public void Dispose()
36
        {
37
            if (this._DbTransaction != null)
38
            {
39
                this._DbTransaction.Commit();
40
            }
41

  
42
            if (this._DbConnection != null)
43
            {
44
                this._DbConnection.Close();
45
            }
46
        }
47

  
48
        protected BaseRepository(string connectionStr)
40
        public SqlConnection DBConnection(string connectionStr)
49 41
        {
50
            this._DbConnection = this.DBConnection(connectionStr);
51

  
52 42
            SqlMapper.TypeMapProvider = type =>
53 43
            {
54 44
                // create fallback default type map
......
69 59
                    return property;
70 60
                });
71 61
            };
62

  
63
            return new SqlConnection(connectionStr);
64
        }
65

  
66
        public SQLiteConnection SQLiteDBConnection(string connectionStr)
67
        {
68
            return new SQLiteConnection(connectionStr);
69
        }
70

  
71
        public IDbTransaction BeginTransaction()
72
        {
73
            if (this._DbConnection.State != ConnectionState.Open)
74
            {
75
                this._DbConnection.Open();
76
            }
77

  
78
            return this._DbConnection.BeginTransaction();
79
        }
80

  
81
        public void Dispose()
82
        {
83
            if (this._DbTransaction != null)
84
            {
85
                this._DbTransaction.Commit();
86
            }
87

  
88
            if (this._DbConnection != null)
89
            {
90
                this._DbConnection.Close();
91
            }
72 92
        }
73 93

  
74 94
        public IEnumerable<T> Query<T>(string sql)

내보내기 Unified diff

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