-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataContext.cs
More file actions
66 lines (49 loc) · 2.09 KB
/
Copy pathDataContext.cs
File metadata and controls
66 lines (49 loc) · 2.09 KB
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
56
57
58
59
60
61
62
63
64
65
66
using CompleteSQL.ConnectionStringParser;
using CompleteSQL.Mapping;
using CompleteSQL.Merge;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace CompleteSQL
{
public class DataContext
{
private readonly SqlConnection m_connection;
public DataContext(string nameOrConnectionString)
{
string connectionString = ((IConnectionStringParser)new ConnectionStringParser.ConnectionStringParser()).Parse(nameOrConnectionString);
m_connection = new SqlConnection(connectionString);
}
public void BulkInsert<TSource>(IEnumerable<TSource> dataSource, string targetTable = null) where TSource: class
{
DataTableCreator dtBuilder = new DataTableCreator();
DataTable dataTable = dtBuilder.Create(dataSource, targetTable);
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(m_connection.ConnectionString))
{
foreach(DataColumn dc in dataTable.Columns)
{
bulkCopy.ColumnMappings.Add(dc.ColumnName, dc.ColumnName);
}
bulkCopy.DestinationTableName = dataTable.TableName;
bulkCopy.WriteToServer(dataTable);
}
}
public MergeClass<TSource> CreateMergeUsing<TSource>(IEnumerable<TSource> usingDataSource) where TSource: class
{
return new MergeClass<TSource>(usingDataSource);
}
public MergeClass<TSource> Merge<TSource, TPredicate>(string target, IEnumerable<TSource> source, Expression<Func<TSource, TPredicate>> mergePredicate)where TSource: class
{
throw new Exception();
}
public MergeClass<TSource> Merge<TSource, TPredicate>(IEnumerable<TSource> source, Expression<Func<TSource, TPredicate>> mergePredicate) where TSource: class
{
throw new NotImplementedException();
}
}
}