Как сопоставить IList C # для списка DynamoDb - PullRequest
0 голосов
/ 27 сентября 2019

У меня есть приложение ASP.Net Core 2.1, которое использует DynamoDb в качестве Db (NoSql)

DTO

public class CustomerTO
{  
 public string Id{get; set;}
 public string Name {get; set;}
 public IList<Contact> Contacts {get; set;}
}


public class Contact
{
 public string Number {get; set;}
 public string Address { get; set;}
}

Я использую API низкого уровня для DynamoDb CRUD.Вот так выглядит мой метод

public async Task<CustomerTO> Add(CustomerTO obj)
    {
        try
        {

            var res = await _dynamoClient.PutItemAsync(tableName: _tableName, item: SetObject(obj));
            if (res.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                return obj;
            }
            else
            {
                //throw new Exception("Error" + res);
            }
        }
        catch (Exception ex)
        {

            Logger.Log(ex);
            return null;
        }
    }

    private Dictionary<string, AttributeValue> SetObject(CustomerTO obj)
    {


        //DynamoDb - Using Low Level API
        var attributes = new Dictionary<string,
        AttributeValue> {
            //Id
            {
                nameof(obj.Id),
                new AttributeValue {
                    S = obj.Id
                }
            },

            //Name
            {
                nameof(obj.Name),
                new AttributeValue {
                    S = obj.Name
                }
            },
            {
                nameof(obj.Contacts),
                new AttributeValue
                {
                   L = new List<AttributeValue(){} //LOE
                }
            }
        };

        return attributes;
    }

Как мне сопоставить поля контактов как L (список) DynamoDb

Спасибо!

...