-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathDbTypeHelper.cs
More file actions
65 lines (61 loc) · 2.37 KB
/
DbTypeHelper.cs
File metadata and controls
65 lines (61 loc) · 2.37 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Data;
namespace Azure.DataApiBuilder.Service.Services
{
/// <summary>
/// Helper class used to resolve the underlying DbType for the parameter for its given SystemType.
/// </summary>
public static class DbTypeHelper
{
private static Dictionary<Type, DbType> _systemTypeToDbTypeMap = new()
{
[typeof(byte)] = DbType.Byte,
[typeof(sbyte)] = DbType.SByte,
[typeof(short)] = DbType.Int16,
[typeof(ushort)] = DbType.UInt16,
[typeof(int)] = DbType.Int32,
[typeof(uint)] = DbType.UInt32,
[typeof(long)] = DbType.Int64,
[typeof(ulong)] = DbType.UInt64,
[typeof(float)] = DbType.Single,
[typeof(double)] = DbType.Double,
[typeof(decimal)] = DbType.Decimal,
[typeof(bool)] = DbType.Boolean,
[typeof(string)] = DbType.String,
[typeof(char)] = DbType.StringFixedLength,
[typeof(Guid)] = DbType.Guid,
[typeof(byte[])] = DbType.Binary,
[typeof(byte?)] = DbType.Byte,
[typeof(sbyte?)] = DbType.SByte,
[typeof(short?)] = DbType.Int16,
[typeof(ushort?)] = DbType.UInt16,
[typeof(int?)] = DbType.Int32,
[typeof(uint?)] = DbType.UInt32,
[typeof(long?)] = DbType.Int64,
[typeof(ulong?)] = DbType.UInt64,
[typeof(float?)] = DbType.Single,
[typeof(double?)] = DbType.Double,
[typeof(decimal?)] = DbType.Decimal,
[typeof(bool?)] = DbType.Boolean,
[typeof(char?)] = DbType.StringFixedLength,
[typeof(Guid?)] = DbType.Guid,
[typeof(object)] = DbType.Object
};
/// <summary>
/// Returns the DbType for given system type.
/// </summary>
/// <param name="systemType">The system type for which the DbType is to be determined.</param>
/// <returns>DbType for the given system type.</returns>
public static DbType? GetDbTypeFromSystemType(Type systemType)
{
if (!_systemTypeToDbTypeMap.TryGetValue(systemType, out DbType dbType))
{
return null;
}
return dbType;
}
}
}