@@ -647,24 +647,12 @@ internal static long Insert<T>(this IDbCommand dbCmd, T obj, Action<IDbCommand>
647
647
648
648
commandFilter ? . Invoke ( dbCmd ) ; //dbCmd.OnConflictInsert() needs to be applied before last insert id
649
649
650
- var modelDef = typeof ( T ) . GetModelDefinition ( ) ;
651
- if ( dialectProvider . HasInsertReturnValues ( modelDef ) )
650
+ if ( dialectProvider . HasInsertReturnValues ( ModelDefinition < T > . Definition ) )
652
651
{
653
652
using ( var reader = dbCmd . ExecReader ( dbCmd . CommandText ) )
654
653
using ( reader )
655
654
{
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 ) ;
668
656
}
669
657
}
670
658
@@ -678,6 +666,24 @@ internal static long Insert<T>(this IDbCommand dbCmd, T obj, Action<IDbCommand>
678
666
return dbCmd . ExecNonQuery ( ) ;
679
667
}
680
668
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
+
681
687
internal static void Insert < T > ( this IDbCommand dbCmd , Action < IDbCommand > commandFilter , params T [ ] objs )
682
688
{
683
689
dbCmd . InsertAll ( objs : objs , commandFilter : commandFilter ) ;
0 commit comments