/
SqlCeQueryProvider.cs
74 lines (63 loc) · 2.33 KB
/
SqlCeQueryProvider.cs
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
67
68
69
70
71
72
73
74
// Copyright (c) Microsoft Corporation. All rights reserved.
// This source code is made available under the terms of the Microsoft Public License (MS-PL)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.Common;
using System.Data.SqlServerCe;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
namespace IQToolkit.Data.SqlServerCe
{
using IQToolkit.Data.Common;
public class SqlCeQueryProvider : DbEntityProvider
{
public SqlCeQueryProvider(SqlCeConnection connection, QueryMapping mapping, QueryPolicy policy)
: base(connection, SqlCeLanguage.Default, mapping, policy)
{
}
public override DbEntityProvider New(DbConnection connection, QueryMapping mapping, QueryPolicy policy)
{
return new SqlCeQueryProvider((SqlCeConnection)connection, mapping, policy);
}
public static string GetConnectionString(string databaseFile)
{
databaseFile = Path.GetFullPath(databaseFile);
return string.Format(@"Data Source='{0}'", databaseFile);
}
protected override QueryExecutor CreateExecutor()
{
return new Executor(this);
}
class Executor : DbEntityProvider.DbQueryExecutor
{
public Executor(SqlCeQueryProvider provider)
: base(provider)
{
}
protected override void AddParameter(DbCommand command, QueryParameter parameter, object value)
{
DbQueryType sqlType = (DbQueryType)parameter.QueryType;
if (sqlType == null)
{
sqlType = (DbQueryType)this.Provider.Language.TypeSystem.GetColumnType(parameter.Type);
}
var p = ((SqlCeCommand)command).Parameters.Add("@" + parameter.Name, sqlType.SqlDbType, sqlType.Length);
if (sqlType.Precision != 0)
{
p.Precision = (byte)sqlType.Precision;
}
if (sqlType.Scale != 0)
{
p.Scale = (byte)sqlType.Scale;
}
p.Value = value ?? DBNull.Value;
}
}
}
}