コード例 #1
0
ファイル: Jaunty.Insert.cs プロジェクト: sbeparey/Jaunty
        private static string Insert <T>(IDictionary <string, object> parameters, bool returnScopeId = false, ITicket ticket = null, bool triggerEvent = false)
        {
            if (parameters is null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (parameters.Count <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(parameters));
            }

            var sql = ticket is null
                                                ? ExtractInsert <T>(parameters, returnScopeId)
                                                : _queriesCache.GetOrAdd(ticket.Id, q => ExtractInsert <T>(parameters, returnScopeId));

            if (!triggerEvent)
            {
                return(sql);
            }

            var eventArgs = new SqlEventArgs {
                Sql = sql, Parameters = parameters
            };

            OnInserting?.Invoke(ticket, eventArgs);
            return(sql);
        }
コード例 #2
0
        private static string InsertUnion <T>(IEnumerable <T> entities, IDictionary <string, object> parameters, ITicket ticket = null, bool triggerEvent = false)
        {
            if (entities is null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            if (parameters is null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (parameters.Count <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(parameters));
            }

            string sql = ticket is null
                                                ? BuildInsertUnionSql(entities)
                                                : _queriesCache.GetOrAdd(ticket.Id, q => BuildInsertUnionSql(entities));

            if (!triggerEvent)
            {
                return(sql);
            }

            var eventArgs = new SqlEventArgs {
                Sql = sql, Parameters = parameters
            };

            OnInserting?.Invoke(ticket, eventArgs);
            return(sql);
        }