Closed michaelmatveev closed 5 years ago
Thanks for reporting this. I was able to reproduce, and I'm looking into how to fix it.
Hi @michaelmatveev, you can get this to work if you instead use
await context.SaveAsync(item, new DynamoDBOperationConfig
{
OverrideTableName = _tableName,
});
I'm concerned that a proper fix to change https://github.com/aws/aws-sdk-net/blob/b691e46e57a3e24477e6a5fa2e849da44db7002f/sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs#L298-L299 to use the contextConfig's value as a backup would be a breaking change. I'll keep this open until I get the team's opinion on this.
I see this issue was closed by our new GitHub automation but I wanted to put some more context into this issue.
You are passing an instance of DynamoDBOperationConfig
into the constructor of DynamoDBContext
. The DynamoDBOperationConfig
type is the one that has the OverrideTable
property but DynamoDBContext
takes in the base class DynamoDBContextConfig
so it has no knowledge of the OverrideTable
property. The DynamoDBOperationConfig
type is meant to be used when calling the individual methods like the SaveAsync
call you are doing so it can override that particular for the POCO being saved to a specific table. The terrible confusion is an artifact of probably a bad design on our part to use inheritance between `DynamoDBContextConfig
and DynamoDBOperationConfig
but at this point we can't change that without very significant breaking changes.
If you are looking for away to do global table mapping changes take a look at using the AWSConfigsDynamoDB.Context.AddMapping
calls. Here is a snippet I did in a recent demo.
In our next major version of the SDK (development underway now, see #3209), we've separated the hierarchy between DynamoDBContextConfig
and DynamoDBOperationConfig
. You will no longer be able to pass an operation-level config in to the context-level constructor, where OverrideTableName
is not honored.
var dynamoDbOperationConfig = new DynamoDBOperationConfig
{
OverrideTableName = _tableName
};
var context = new DynamoDBContext(_client, dynamoDbOperationConfig); // no longer possible in V4
We didn't want to take a single override table name as an input to the context object, since one can reuse a context object with multiple tables. If you do want to override table names on an application-level, you can use the TableAlias
or TypeMapping
collections on AWSConfigsDynamoDB.Context
.
Expected Behavior
Suppose I create DynamoDBContext like follows
then I try to use context expecting to save an item with a class name different then a table name
Current Behavior
Get an error
Possible Solution
Fix in the \sdk\src\Services\DynamoDBv2\Custom\DataModel\Configs.cs:
Steps to Reproduce (for bugs)
and the test
Context
Workaround is to pass DynamoDBOperationConfig to each operation
Your Environment
.NET Core Info
Runtime Environment: OS Name: Windows Server 2016 Standard OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.503\
Host (useful for support): Version: 2.1.7 Commit: cca5d72d48
.NET Core SDKs installed: 1.1.9 [C:\Program Files\dotnet\sdk] 2.1.2 [C:\Program Files\dotnet\sdk] 2.1.200 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.300 [C:\Program Files\dotnet\sdk] 2.1.400 [C:\Program Files\dotnet\sdk] 2.1.402 [C:\Program Files\dotnet\sdk] 2.1.503 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]