简体   繁体   中英

AWS DynamoDB: query works on the console but not on .NET Code

I have a DynamoDB query that works fine on the AWS Console but it doesn't on code.

Here is my query on the console: 在此处输入图片说明

Now here is my c# code to query it:

var query = new QueryOperationConfig
            {
                KeyExpression = new Expression
                {
                    ExpressionStatement = "#pkey = :v_pkey and #skey >= :v_skey",
                    ExpressionAttributeNames = {
                        { "#pkey", "MailingId" },
                        { "#skey", "RegistroCarteiraId" },
                    },
                    ExpressionAttributeValues = new Dictionary<string, DynamoDBEntry>()
                    {
                        { ":v_pkey", new Primitive("62", true) },
                        { ":v_skey", new Primitive("00e0bbfc-aed0-4f0e-acef-a3623a9f9694") },
                    },
                },
                BackwardSearch = false,
                ConsistentRead = true,
                Limit = 1,
                FilterExpression = new Expression
                {
                    ExpressionStatement = "#psituacao = :v_psituacao and attribute_not_exists(#pdisponibilidade)",
                    ExpressionAttributeNames =
                    {
                        { "#psituacao", "Situacao" },
                        { "#pdisponibilidade", "Disponibilidade" }
                    },
                    ExpressionAttributeValues =
                    {
                        { ":v_psituacao", new Primitive("1", true) },
                    }
                }
            };

            var search = table.Query(query);
            var docs = await search.GetNextSetAsync();

I get no errors, only an empty array as the result. If I change the sort key to different values, it works, but for this particular value it does not...

I've been at it all day and couldn't figure it out what is wrong.

Any help will be much appreciated.

Thanks

The problem was the LIMIT 1 .

As I found out, the filter only happens on the fetched items and, since I was only fetching 1 item, when the filter occurred, the result had no records that matched the criteria.

Removing the Limit 1 solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM