Пример #1
0
        public string Insert(Type type, string tableName)
        {
            var key = $"{nameof(Insert)}_{type.FullName}_{tableName}";

            return(_sqlsCache.GetOrAdd(key, () =>
            {
                var tableInfo = _mapper.GetEntityTableInfo(type);
                var paramPrefix = _sqlAdapter.GetParameterPrefix();

                if (string.IsNullOrEmpty(tableName))
                {
                    tableName = tableInfo.TableName;
                }
                tableName = _sqlAdapter.EscapeTableName(tableName);
                var insertCols = tableInfo.Columns.Where(p => !p.IsAutoIncrement).ToList();
                var iColsName = string.Join(", ", insertCols.Select(p => _sqlAdapter.EscapeSqlIdentifier(p.ColumnName)));
                var iColsParams = string.Join(", ", insertCols.Select(p => paramPrefix + p.Property.Name));
                return $"insert into {tableName} ({iColsName}) values ({iColsParams})";
            }));
        }