1313
1414#if EF5
1515using System . Data . Objects ;
16+ using System . Data . SqlClient ;
1617#elif EF6
18+ using System . Data . SqlClient ;
1719#elif EFCORE
1820using Microsoft . EntityFrameworkCore . Storage ;
21+ using Microsoft . EntityFrameworkCore . Storage . Internal ;
1922#endif
2023
2124namespace Z . EntityFramework . Plus
@@ -35,6 +38,17 @@ public static void CopyFrom(this DbParameter @this, DbParameter from)
3538 @this . ParameterName = from . ParameterName ;
3639 @this . Size = from . Size ;
3740
41+ #if ! EFCORE
42+ if ( from is SqlParameter )
43+ {
44+ var fromSql = ( SqlParameter ) from ;
45+ var toSql = ( SqlParameter ) @this ;
46+
47+ toSql . SqlDbType = fromSql . SqlDbType ;
48+ toSql . UdtTypeName = fromSql . UdtTypeName ;
49+ }
50+ #endif
51+
3852#if EF6
3953 if ( fullName . Contains ( "Oracle" ) && from . GetType ( ) . GetProperty ( "OracleDbType" ) != null )
4054 {
@@ -59,6 +73,17 @@ public static void CopyFrom(this DbParameter @this, DbParameter from, string new
5973 @this . ParameterName = newParameterName ;
6074 @this . Size = from . Size ;
6175
76+ #if ! EFCORE
77+ if ( from is SqlParameter )
78+ {
79+ var fromSql = ( SqlParameter ) from ;
80+ var toSql = ( SqlParameter ) @this ;
81+
82+ toSql . SqlDbType = fromSql . SqlDbType ;
83+ toSql . UdtTypeName = fromSql . UdtTypeName ;
84+ }
85+ #endif
86+
6287#if EF6
6388 if ( fullName . Contains ( "Oracle" ) && from . GetType ( ) . GetProperty ( "OracleDbType" ) != null )
6489 {
@@ -90,13 +115,43 @@ public static void CopyFrom(this DbParameter @this, IRelationalParameter from, o
90115 {
91116 @this . ParameterName = from . InvariantName ;
92117
118+ if ( from is TypeMappedRelationalParameter )
119+ {
120+ var relationalTypeMappingProperty = typeof ( TypeMappedRelationalParameter ) . GetProperty ( "RelationalTypeMapping" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) ;
121+
122+ if ( relationalTypeMappingProperty != null )
123+ {
124+ var relationalTypeMapping = ( RelationalTypeMapping ) relationalTypeMappingProperty . GetValue ( from ) ;
125+
126+ if ( relationalTypeMapping . DbType . HasValue )
127+ {
128+ @this . DbType = relationalTypeMapping . DbType . Value ;
129+ }
130+ }
131+ }
132+
93133 @this . Value = value ?? DBNull . Value ;
94134 }
95135
96136 public static void CopyFrom ( this DbParameter @this , IRelationalParameter from , object value , string newParameterName )
97137 {
98138 @this . ParameterName = newParameterName ;
99139
140+ if ( from is TypeMappedRelationalParameter )
141+ {
142+ var relationalTypeMappingProperty = typeof ( TypeMappedRelationalParameter ) . GetProperty ( "RelationalTypeMapping" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) ;
143+
144+ if ( relationalTypeMappingProperty != null )
145+ {
146+ var relationalTypeMapping = ( RelationalTypeMapping ) relationalTypeMappingProperty . GetValue ( from ) ;
147+
148+ if ( relationalTypeMapping . DbType . HasValue )
149+ {
150+ @this . DbType = relationalTypeMapping . DbType . Value ;
151+ }
152+ }
153+ }
154+
100155 @this . Value = value ?? DBNull . Value ;
101156 }
102157#endif
0 commit comments