@@ -647,24 +647,12 @@ internal static long Insert<T>(this IDbCommand dbCmd, T obj, Action<IDbCommand>
647647
648648 commandFilter ? . Invoke ( dbCmd ) ; //dbCmd.OnConflictInsert() needs to be applied before last insert id
649649
650- var modelDef = typeof ( T ) . GetModelDefinition ( ) ;
651- if ( dialectProvider . HasInsertReturnValues ( modelDef ) )
650+ if ( dialectProvider . HasInsertReturnValues ( ModelDefinition < T > . Definition ) )
652651 {
653652 using ( var reader = dbCmd . ExecReader ( dbCmd . CommandText ) )
654653 using ( reader )
655654 {
656- if ( reader . Read ( ) )
657- {
658- var values = new object [ reader . FieldCount ] ;
659- var indexCache = reader . GetIndexFieldsCache ( ModelDefinition < T > . Definition , dialectProvider ) ;
660- obj . PopulateWithSqlReader ( dialectProvider , reader , indexCache , values ) ;
661- if ( ( modelDef . PrimaryKey != null ) && modelDef . PrimaryKey . AutoIncrement )
662- {
663- var id = modelDef . GetPrimaryKey ( obj ) ;
664- return Convert . ToInt64 ( id ) ;
665- }
666- }
667- return 0 ;
655+ return reader . PopulateReturnValues ( dialectProvider , obj ) ;
668656 }
669657 }
670658
@@ -678,6 +666,24 @@ internal static long Insert<T>(this IDbCommand dbCmd, T obj, Action<IDbCommand>
678666 return dbCmd . ExecNonQuery ( ) ;
679667 }
680668
669+ internal static long PopulateReturnValues < T > ( this IDataReader reader , IOrmLiteDialectProvider dialectProvider , T obj )
670+ {
671+ if ( reader . Read ( ) )
672+ {
673+ var modelDef = ModelDefinition < T > . Definition ;
674+ var values = new object [ reader . FieldCount ] ;
675+ var indexCache = reader . GetIndexFieldsCache ( modelDef , dialectProvider ) ;
676+ obj . PopulateWithSqlReader ( dialectProvider , reader , indexCache , values ) ;
677+ if ( ( modelDef . PrimaryKey != null ) && modelDef . PrimaryKey . AutoIncrement )
678+ {
679+ var id = modelDef . GetPrimaryKey ( obj ) ;
680+ return Convert . ToInt64 ( id ) ;
681+ }
682+ }
683+
684+ return 0 ;
685+ }
686+
681687 internal static void Insert < T > ( this IDbCommand dbCmd , Action < IDbCommand > commandFilter , params T [ ] objs )
682688 {
683689 dbCmd . InsertAll ( objs : objs , commandFilter : commandFilter ) ;
0 commit comments