44using System ;
55using System . Collections . Generic ;
66using System . Linq ;
7+ using System . Data ;
78
89namespace DataBoss
910{
@@ -59,37 +60,36 @@ public static ICollection<int> InsertAndGetIdentities<T>(this SqlConnection conn
5960 bulkCopy . WriteToServer ( toInsert ) ;
6061
6162 var columns = string . Join ( "," , Enumerable . Range ( 1 , toInsert . FieldCount - 1 ) . Select ( toInsert . GetName ) ) ;
62- var reader = new DbObjectReader ( connection ) {
63- CommandTimeout = null ,
64- } ;
65- return reader . Read < IdRow > ( $@ "
63+ using ( var cmd = connection . CreateCommand ( $@ "
6664 insert { destinationTable } with(tablock)({ columns } )
6765 output inserted.$identity as { nameof ( IdRow . Id ) }
6866 select { columns }
6967 from { TempTableName }
7068 order by [$]
7169
7270 drop table { TempTableName }
73- " ) . OrderBy ( x => x . Id ) . Select ( x => x . Id ) . ToList ( ) ;
71+ " ) ) {
72+ cmd . CommandTimeout = 0 ;
73+ using ( var reader = ObjectReader . For ( cmd . ExecuteReader ( CommandBehavior . SingleResult | CommandBehavior . SequentialAccess ) ) )
74+ return reader . Read < IdRow > ( ) . OrderBy ( x => x . Id ) . Select ( x => x . Id ) . ToList ( ) ;
75+ }
7476 }
7577
7678 public static void WithCommand ( this SqlConnection connection , Action < SqlCommand > useCommand ) {
7779 using ( var cmd = connection . CreateCommand ( ) )
7880 useCommand ( cmd ) ;
7981 }
8082
81- public static DatabaseInfo GetDatabaseInfo ( this SqlConnection connection )
82- {
83+ public static DatabaseInfo GetDatabaseInfo ( this SqlConnection connection ) {
8384 var reader = new DbObjectReader ( connection ) ;
84- return reader . Single < DatabaseInfo > (
85- @"select
86- ServerName = serverproperty('ServerName'),
87- ServerVersion = serverproperty('ProductVersion'),
88- DatabaseName = db.name,
89- DatabaseId = db.database_id,
90- CompatibilityLevel = db.compatibility_level
91- from sys.databases db where database_id = db_id()"
92- ) ;
85+ return reader . Single < DatabaseInfo > ( @"
86+ select
87+ ServerName = serverproperty('ServerName'),
88+ ServerVersion = serverproperty('ProductVersion'),
89+ DatabaseName = db.name,
90+ DatabaseId = db.database_id,
91+ CompatibilityLevel = db.compatibility_level
92+ from sys.databases db where database_id = db_id()" ) ;
9393 }
9494 }
9595}
0 commit comments