1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Data ;
4
+ using System . Data . Common ;
5
+ using System . Data . SqlClient ;
6
+ using System . Linq ;
7
+ using System . Reflection ;
8
+ using System . Text ;
9
+ namespace SqlSugar
10
+ {
11
+ public partial class AdoAccessory
12
+ {
13
+ protected IDbBind _DbBind ;
14
+ protected IDbFirst _DbFirst ;
15
+ protected ICodeFirst _CodeFirst ;
16
+ protected IDbMaintenance _DbMaintenance ;
17
+ protected IDbConnection _DbConnection ;
18
+
19
+ protected virtual SugarParameter [ ] GetParameters ( object parameters , PropertyInfo [ ] propertyInfo , string sqlParameterKeyWord )
20
+ {
21
+ List < SugarParameter > result = new List < SugarParameter > ( ) ;
22
+ if ( parameters != null )
23
+ {
24
+ var entityType = parameters . GetType ( ) ;
25
+ var isDictionary = entityType . IsIn ( UtilConstants . DicArraySO , UtilConstants . DicArraySS ) ;
26
+ if ( isDictionary )
27
+ DictionaryToParameters ( parameters , sqlParameterKeyWord , result , entityType ) ;
28
+ else if ( parameters is List < SugarParameter > )
29
+ {
30
+ result = ( parameters as List < SugarParameter > ) ;
31
+ }
32
+ else if ( parameters is SugarParameter [ ] )
33
+ {
34
+ result = ( parameters as SugarParameter [ ] ) . ToList ( ) ;
35
+ }
36
+ else
37
+ {
38
+ Check . Exception ( ! entityType . IsAnonymousType ( ) , "The parameter format is wrong. \n Use new{{xx=xx, xx2=xx2}} or \n Dictionary<string, object> or \n SugarParameter [] " ) ;
39
+ ProperyToParameter ( parameters , propertyInfo , sqlParameterKeyWord , result , entityType ) ;
40
+ }
41
+ }
42
+ return result . ToArray ( ) ;
43
+ }
44
+ protected void ProperyToParameter ( object parameters , PropertyInfo [ ] propertyInfo , string sqlParameterKeyWord , List < SugarParameter > listParams , Type entityType )
45
+ {
46
+ PropertyInfo [ ] properties = null ;
47
+ if ( propertyInfo != null )
48
+ properties = propertyInfo ;
49
+ else
50
+ properties = entityType . GetProperties ( ) ;
51
+
52
+ foreach ( PropertyInfo properyty in properties )
53
+ {
54
+ var value = properyty . GetValue ( parameters , null ) ;
55
+ if ( properyty . PropertyType . IsEnum ( ) )
56
+ value = Convert . ToInt64 ( value ) ;
57
+ if ( value == null || value . Equals ( DateTime . MinValue ) ) value = DBNull . Value ;
58
+ if ( properyty . Name . ToLower ( ) . Contains ( "hierarchyid" ) )
59
+ {
60
+ var parameter = new SugarParameter ( sqlParameterKeyWord + properyty . Name , SqlDbType . Udt ) ;
61
+ parameter . UdtTypeName = "HIERARCHYID" ;
62
+ parameter . Value = value ;
63
+ listParams . Add ( parameter ) ;
64
+ }
65
+ else
66
+ {
67
+ var parameter = new SugarParameter ( sqlParameterKeyWord + properyty . Name , value ) ;
68
+ listParams . Add ( parameter ) ;
69
+ }
70
+ }
71
+ }
72
+ protected void DictionaryToParameters ( object parameters , string sqlParameterKeyWord , List < SugarParameter > listParams , Type entityType )
73
+ {
74
+ if ( entityType == UtilConstants . DicArraySO )
75
+ {
76
+ var dictionaryParameters = ( Dictionary < string , object > ) parameters ;
77
+ var sugarParameters = dictionaryParameters . Select ( it => new SugarParameter ( sqlParameterKeyWord + it . Key , it . Value ) ) ;
78
+ listParams . AddRange ( sugarParameters ) ;
79
+ }
80
+ else
81
+ {
82
+ var dictionaryParameters = ( Dictionary < string , string > ) parameters ;
83
+ var sugarParameters = dictionaryParameters . Select ( it => new SugarParameter ( sqlParameterKeyWord + it . Key , it . Value ) ) ;
84
+ listParams . AddRange ( sugarParameters ) ; ;
85
+ }
86
+ }
87
+ }
88
+ }
0 commit comments