Код: Выделить всё
ResourcesResponse instantiation:
Код: Выделить всё
var tmp = new ResourcesResponse
{
Cost = aux.Sum(s => s.Cost),
Resources = aux
.OrderBy(k => k.Order)
.ThenBy(k => k.TypeId)
.Select(async s => new ResourcesResponse.Resource
{
Id = ((ulong)s.Id).ToString(),
Charge = s.Charge,
Cost = s.Cost,
CurrencyCode = s.CurrencyCode,
ForecastCharge = s.ForecastCharge,
ForecastCost = s.ForecastCost,
ForecastUsedUnits = s.ForecastUsedUnits,
ParentId = ((ulong?)s.ParentId).ToString(),
Order = await _resourcesRepository.GetResourceTypeOrder(s.TypeId),
Rate = s.Rate,
TypeId = s.TypeId,
UsedUnits = s.UsedUnits,
})
.ToArray(),
Id = ((ulong)entry.Id).ToString(),
Name = entry.Name,
Description = entry.Description,
OriginalId = entry.OriginalId,
ResourceTypeId = entry.ResourceTypeId,
ResourceType = await _resourcesRepository.GetResourceTypeName(entry.ResourceTypeId),
Order = await _resourcesRepository.GetResourceTypeOrder(entry.ResourceTypeId),
State = entry.State,
Zone = entry.Zone,
Charge = aux.Sum(s => s.Charge),
};
Код: Выделить всё
ResourceResponse:
Код: Выделить всё
public class ResourcesResponse
{
public string Id { get; set; } = default!;
public string Name { get; set; } = default!;
public string? Description { get; set; } = default!;
public string OriginalId { get; set; } = default!;
public string ResourceType { get; set; } = default!;
[JsonIgnore]
public int? Order { get; set; } = default!;
public ResourceTypeValues ResourceTypeId { get; set; }
public string? CurrencyCode => Resources?.FirstOrDefault()?.CurrencyCode;
public decimal? Charge { get; set; }
public decimal Cost { get; set; }
public decimal? ForecastCharge { get; set; }
public decimal? ForecastCost { get; set; }
public string Zone { get; set; } = default!;
public string State { get; set; } = default!;
public Resource[] Resources { get; set; } = default!;
public sealed class Resource
{
[JsonIgnore]
public string Id { get; set; } = default!;
[JsonIgnore]
public string? ParentId { get; set; } = default!;
[JsonIgnore]
public int? Order { get; set; } = default!;
public string CurrencyCode { get; set; } = default!;
public decimal Rate { get; set; }
public long UsedUnits { get; set; }
public decimal Cost { get; set; }
public decimal? Charge { get; set; }
public long? ForecastUsedUnits { get; set; }
public decimal? ForecastCost { get; set; }
public decimal? ForecastCharge { get; set; }
public string Type { get; set; } = default!;
public ResourceTypeValues TypeId { get; set; }
public string? Unit { get; set; } = default!;
public bool? Hourly { get; set; } = default!;
}
}
Код: Выделить всё
ResourceTypeOrder:
Код: Выделить всё
public async Task GetResourceTypeOrder(ResourceTypeValues resourceTypeId)
{
ICache.Operation myTableCacheImplementation = async delegate (string key)
{
var dic = await _repositoryResourceTypes.FindAll().ToDictionaryAsync(k => k.Id);
return dic[resourceTypeId].Order;
};
return await _vdcCache.GetOrCreateAsync(ResourceTypeCacheKey.ResourceTypeOrder, myTableCacheImplementation, null);
}

Мой проблема в том, что я не знаю, куда поместить недостающий await (или что-то еще, что необходимо для того, чтобы все выражение было принято компилятором).
Для родительский ResourceResponse также есть вычисляемое поле Order, но, как вы можете видеть, оно правильное.
Очевидно, что я можно было бы добавить .Result в конец GetResourceTypeOrder и удалить оператор async, но это не идея async/await.
Подробнее здесь: https://stackoverflow.com/questions/789 ... -compiling