コード例 #1
0
        internal static IDbCommand InsertIntoSelectInternal <T>(this IDbCommand dbCmd, ISqlExpression query, Action <IDbCommand> commandFilter)
        {
            var dialectProvider = dbCmd.GetDialectProvider();

            var sql          = query.ToSelectStatement();
            var selectFields = query.GetUntypedSqlExpression()
                               .SelectExpression
                               .Substring("SELECT ".Length)
                               .ParseCommands();

            var fieldsOrAliases = selectFields
                                  .Map(x => x.Original.ToString().LastRightPart(" AS ").Trim().StripDbQuotes());

            dialectProvider.PrepareParameterizedInsertStatement <T>(dbCmd, insertFields: fieldsOrAliases);

            dbCmd.SetParameters(query.Params);

            dbCmd.CommandText = dbCmd.CommandText.LeftPart(")") + ")\n" + sql;

            commandFilter?.Invoke(dbCmd); //dbCmd.OnConflictInsert() needs to be applied before last insert id
            return(dbCmd);
        }