@@ -201,12 +201,73 @@ INSERT INTO {Tables.Episodes}
201201 await connection . ExecuteAsync ( Tables . DeleteTables ) ;
202202 }
203203
204+ [ Fact ]
205+ public async Task NullableFieldSupported ( )
206+ {
207+ var tableName = "DapperNullableTypes_" + Random . Shared . Next ( ) ;
208+
209+ await using var connection = new YdbConnection ( ) ;
210+ await connection . ExecuteAsync ( @$ "
211+ CREATE TABLE { tableName } (
212+ Id INT32,
213+ BoolColumn BOOL,
214+ LongColumn INT64,
215+ ShortColumn INT16,
216+ SbyteColumn INT8,
217+ FloatColumn FLOAT,
218+ DoubleColumn DOUBLE,
219+ DecimalColumn DECIMAL(22,9),
220+ ByteColumn UINT8,
221+ UshortColumn UINT16,
222+ UintColumn UINT32,
223+ UlongColumn UINT64,
224+ TextColumn TEXT,
225+ BytesColumn BYTES,
226+ TimestampColumn TIMESTAMP,
227+ PRIMARY KEY (Id)
228+ )
229+ " ) ;
230+
231+ var entity = new NullableFields ( ) ;
232+ SqlMapper . AddTypeMap ( typeof ( DateTime ) , DbType . DateTime2 ) ;
233+
234+ await connection . ExecuteAsync ( $@ "
235+ INSERT INTO { tableName } (Id, BoolColumn, LongColumn, ShortColumn, SbyteColumn, FloatColumn, DoubleColumn, DecimalColumn,
236+ ByteColumn, UshortColumn, UintColumn, UlongColumn, TextColumn, BytesColumn, TimestampColumn)
237+ VALUES (@Id, @BoolColumn, @LongColumn, @ShortColumn, @SbyteColumn,
238+ @FloatColumn, @DoubleColumn, @DecimalColumn,
239+ @ByteColumn, @UshortColumn, @UintColumn,
240+ @UlongColumn, @TextColumn, @BytesColumn, @TimestampColumn)" , entity ) ;
241+
242+ Assert . Equal ( entity ,
243+ await connection . QuerySingleAsync < NullableFields > ( $ "SELECT * FROM { tableName } WHERE Id IS NULL") ) ;
244+ }
245+
246+ private record NullableFields
247+ {
248+ public int ? Id { get ; init ; }
249+ public bool ? BoolColumn { get ; init ; }
250+ public long ? LongColumn { get ; init ; }
251+ public short ? ShortColumn { get ; init ; }
252+ public sbyte ? SbyteColumn { get ; init ; }
253+ public float ? FloatColumn { get ; init ; }
254+ public double ? DoubleColumn { get ; init ; }
255+ public decimal ? DecimalColumn { get ; init ; }
256+ public byte ? ByteColumn { get ; init ; }
257+ public ushort ? UshortColumn { get ; init ; }
258+ public uint ? UintColumn { get ; init ; }
259+ public ulong ? UlongColumn { get ; init ; }
260+ public string ? TextColumn { get ; init ; }
261+ public byte [ ] ? BytesColumn { get ; init ; }
262+ public DateTime ? TimestampColumn { get ; init ; }
263+ }
264+
204265 private record Episode
205266 {
206- [ Column ( "series_id" ) ] public uint SeriesId { get ; set ; }
207- [ Column ( "season_id" ) ] public uint SeasonId { get ; set ; }
208- [ Column ( "episode_id" ) ] public uint EpisodeId { get ; set ; }
209- [ Column ( "title" ) ] public string Title { get ; set ; } = null ! ;
210- [ Column ( "air_date" ) ] public DateTime AirDate { get ; set ; }
267+ [ Column ( "series_id" ) ] public uint SeriesId { get ; init ; }
268+ [ Column ( "season_id" ) ] public uint SeasonId { get ; init ; }
269+ [ Column ( "episode_id" ) ] public uint EpisodeId { get ; init ; }
270+ [ Column ( "title" ) ] public string Title { get ; init ; } = null ! ;
271+ [ Column ( "air_date" ) ] public DateTime AirDate { get ; init ; }
211272 }
212273}
0 commit comments