@@ -61,7 +61,8 @@ public override void ResetDbType()
6161 }
6262
6363 public override DbType DbType { get ; set ; } = DbType . Object ;
64- public override ParameterDirection Direction { get ; set ; } = ParameterDirection . InputOutput ;
64+ public override ParameterDirection Direction { get ; set ; } = ParameterDirection . Input ;
65+ public override DataRowVersion SourceVersion { get ; set ; } = DataRowVersion . Current ;
6566 public override bool IsNullable { get ; set ; }
6667
6768 [ AllowNull ]
@@ -73,15 +74,24 @@ public override string ParameterName
7374 {
7475 _parameterName = value switch
7576 {
76- null => throw new YdbException ( "ParameterName must not be null!" ) ,
77+ null => string . Empty ,
7778 _ when value . StartsWith ( "$" ) => value ,
7879 _ when value . StartsWith ( "@" ) && value . Length > 1 => $ "${ value [ 1 ..] } ",
7980 _ => $ "${ value } "
8081 } ;
8182 }
8283 }
8384
84- [ AllowNull ] [ DefaultValue ( "" ) ] public override string SourceColumn { get ; set ; } = string . Empty ;
85+ private string _sourceColumn = string . Empty ;
86+
87+ [ AllowNull ]
88+ [ DefaultValue ( "" ) ]
89+ public override string SourceColumn
90+ {
91+ get => _sourceColumn ;
92+ set => _sourceColumn = value ?? string . Empty ;
93+ }
94+
8595 public override object ? Value { get ; set ; }
8696 public override bool SourceColumnNullMapping { get ; set ; }
8797 public override int Size { get ; set ; }
@@ -102,22 +112,22 @@ string valueString when DbType is DbType.String or DbType.AnsiString or DbType.A
102112 DbType . Date => YdbValue . MakeDate ( dateTimeValue ) ,
103113 DbType . DateTime => YdbValue . MakeDatetime ( dateTimeValue ) ,
104114 DbType . DateTime2 or DbType . Object => YdbValue . MakeTimestamp ( dateTimeValue ) ,
105- _ => ThrowInvalidCast ( )
115+ _ => ThrowInvalidOperation ( )
106116 } ,
107117 DateTimeOffset dateTimeOffset when DbType is DbType . DateTimeOffset or DbType . Object =>
108118 YdbValue . MakeTimestamp ( dateTimeOffset . UtcDateTime ) ,
109119 float floatValue => DbType switch
110120 {
111121 DbType . Single or DbType . Object => YdbValue . MakeFloat ( floatValue ) ,
112122 DbType . Double => YdbValue . MakeDouble ( floatValue ) ,
113- _ => ThrowInvalidCast ( )
123+ _ => ThrowInvalidOperation ( )
114124 } ,
115125 double doubleValue when DbType is DbType . Double or DbType . Object => YdbValue . MakeDouble ( doubleValue ) ,
116126 int intValue => DbType switch
117127 {
118128 DbType . Int32 or DbType . Object => YdbValue . MakeInt32 ( intValue ) ,
119129 DbType . Int64 => YdbValue . MakeInt64 ( intValue ) ,
120- _ => ThrowInvalidCast ( )
130+ _ => ThrowInvalidOperation ( )
121131 } ,
122132 long longValue when DbType is DbType . Int64 or DbType . Object => YdbValue . MakeInt64 ( longValue ) ,
123133 decimal decimalValue when DbType is DbType . Decimal or DbType . Currency or DbType . Object =>
@@ -128,7 +138,7 @@ string valueString when DbType is DbType.String or DbType.AnsiString or DbType.A
128138 DbType . UInt32 or DbType . Object => YdbValue . MakeUint32 ( uintValue ) ,
129139 DbType . UInt64 => YdbValue . MakeUint64 ( uintValue ) ,
130140 DbType . Int64 => YdbValue . MakeInt64 ( uintValue ) ,
131- _ => ThrowInvalidCast ( )
141+ _ => ThrowInvalidOperation ( )
132142 } ,
133143 byte byteValue => DbType switch
134144 {
@@ -139,15 +149,15 @@ string valueString when DbType is DbType.String or DbType.AnsiString or DbType.A
139149 DbType . UInt64 => YdbValue . MakeUint64 ( byteValue ) ,
140150 DbType . UInt32 => YdbValue . MakeUint32 ( byteValue ) ,
141151 DbType . UInt16 => YdbValue . MakeUint16 ( byteValue ) ,
142- _ => ThrowInvalidCast ( )
152+ _ => ThrowInvalidOperation ( )
143153 } ,
144154 sbyte sbyteValue => DbType switch
145155 {
146156 DbType . SByte or DbType . Object => YdbValue . MakeInt8 ( sbyteValue ) ,
147157 DbType . Int64 => YdbValue . MakeInt64 ( sbyteValue ) ,
148158 DbType . Int32 => YdbValue . MakeInt32 ( sbyteValue ) ,
149159 DbType . Int16 => YdbValue . MakeInt16 ( sbyteValue ) ,
150- _ => ThrowInvalidCast ( )
160+ _ => ThrowInvalidOperation ( )
151161 } ,
152162 ushort ushortValue => DbType switch
153163 {
@@ -156,27 +166,29 @@ string valueString when DbType is DbType.String or DbType.AnsiString or DbType.A
156166 DbType . Int32 => YdbValue . MakeInt32 ( ushortValue ) ,
157167 DbType . UInt64 => YdbValue . MakeUint64 ( ushortValue ) ,
158168 DbType . UInt32 => YdbValue . MakeUint32 ( ushortValue ) ,
159- _ => ThrowInvalidCast ( )
169+ _ => ThrowInvalidOperation ( )
160170 } ,
161171 short shortValue => DbType switch
162172 {
163173 DbType . Int16 or DbType . Object => YdbValue . MakeInt16 ( shortValue ) ,
164174 DbType . Int64 => YdbValue . MakeInt64 ( shortValue ) ,
165175 DbType . Int32 => YdbValue . MakeInt32 ( shortValue ) ,
166- _ => ThrowInvalidCast ( )
176+ _ => ThrowInvalidOperation ( )
167177 } ,
168178 byte [ ] bytesValue when DbType is DbType . Binary or DbType . Object => YdbValue . MakeString ( bytesValue ) ,
169179 Guid guidValue when DbType is DbType . Guid or DbType . Object => YdbValue . MakeUuid ( guidValue ) ,
180+ MemoryStream memoryStream when DbType is DbType . Binary or DbType . Object => YdbValue . MakeString (
181+ memoryStream . ToArray ( ) ) ,
170182 _ when DbType is DbType . VarNumeric or DbType . Xml or DbType . Time =>
171183 throw new YdbException ( $ "Ydb don't supported this DbType: { DbType } ") ,
172- _ => ThrowInvalidCast ( )
184+ _ => ThrowInvalidOperation ( )
173185 } ;
174186 }
175187 }
176188
177- private YdbValue ThrowInvalidCast ( )
189+ private YdbValue ThrowInvalidOperation ( )
178190 {
179- throw new InvalidCastException (
191+ throw new InvalidOperationException (
180192 $ "Writing value of '{ Value ? . GetType ( ) . ToString ( ) ?? "null" } ' is not supported for parameters having DbType '{ DbType } '") ;
181193 }
182194}
0 commit comments