efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Cosmos: Pipe character is escaped for key value when creating a new document

Open nellstephanj opened this issue 6 years ago • 3 comments

We receive an id from a third party application where the format of the id is <name>|<guid> for example "test|36f47ad4-e23f-43f1-8c37-304df4e6193a".

When creating a document and marking this value as the key-value EF escapes the pipe character for the id so the example ends up being test/|36f47ad4-e23f-43f1-8c37-304df4e6193a. If the value is not marked as the key-value it is not escaped. Using EF to retrieve the same document works fine however when viewing the values using the Azure Data Explorer it breaks with the following message:

image

When creating the same document using the same key using the Cosmos SDK the character is not escaped and I am able to view the document using Azure Data Explorer.

The fluent setup I used

builder.Property(user => user.UserId).HasMaxLength(100);
builder.HasKey(user => user.UserId);
builder.HasPartitionKey(user => user.regionCode);

and saving the user

    context.Add(new User
    {
        UserId = "test|36f47ad4-ef3f-43f1-8c67-304df4e6193a",
        Name= "Test",
        regionCode = "1-Test"
    });

    await context.SaveChangesAsync()

Further technical details

EF Core version: 3.1.3 EF Core.Cosmos version 3.1.3 Target framework: NET Core 3.1

nellstephanj avatar Apr 17 '20 12:04 nellstephanj

These characters can't be used in the resource id: '/', '\', '?', '#', source We can instead url encode the '|' char, but that might be blocked by https://github.com/Azure/azure-cosmos-dotnet-v2/issues/458

AndriySvyryd avatar Apr 17 '20 18:04 AndriySvyryd

Is this slated for the next release?

vsadams avatar Jun 15 '20 12:06 vsadams

@vsadams Yes

AndriySvyryd avatar Jun 15 '20 17:06 AndriySvyryd