Exemplo n.º 1
0
        private async Task SaveManyCoreMany(IDbFactory dbFactory,
                                            IEnumerable <StateEntity> entities)
        {
            var array = StateEntity.DistinctWithVersion(entities).ToArray();
            var items = array
                        .Select(x => new RelationalStateEntity
            {
                claptrap_id        = x.ClaptrapId,
                claptrap_type_code = x.ClaptrapTypeCode,
                version            = x.Version,
                state_data         = x.StateData,
                updated_time       = x.UpdatedTime
            })
                        .AsParallel()
                        .ToArray();

            var sql = GetUpsertSql(_schemaName, _tableName, items.Length);

            await using var db = dbFactory.GetConnection(_connectionName);
            var ps = new DynamicParameters();

            for (var i = 0; i < array.Length; i++)
            {
                foreach (var(parameterName, valueFunc) in RelationalStateEntity.ValueFactories())
                {
                    var entity = items[i];
                    var name   = _sqlTemplateCache.GetOrAddGetParameterName(parameterName, i);
                    ps.Add(name, valueFunc(entity));
                }
            }

            await db.ExecuteAsync(sql, ps);
        }
Exemplo n.º 2
0
        private string ValuePartFactory(IEnumerable <string> parameters, int index)
        {
            var values = string.Join(",", parameters.Select(x =>
                                                            _sqlTemplateCache.GetOrAddGetParameterName(x, index)));
            var re = $" ({values}) ";

            return(re);
        }