Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Cosmos] How to set a partition key in a embedded entity? #25548

Open
silverio27 opened this issue Aug 17, 2021 · 0 comments
Open

[Cosmos] How to set a partition key in a embedded entity? #25548

silverio27 opened this issue Aug 17, 2021 · 0 comments
Labels
area-cosmos customer-reported punted-for-9.0 Originally planned for the EF Core 9.0 (EF9) release, but moved out due to resource constraints. type-enhancement
Milestone

Comments

@silverio27
Copy link

I have a Post entity that has an Author as a embedded entity. I would like the Author Id to be my partition key. But when I try to do this through fluent api I get the error below:

Im try this:

 builder.HasPartitionKey(x => x.Author.UserId);

and i get this:

System.ArgumentException: 'The expression 'x => x.Author.UserId' is not a valid member access expression. The expression should represent a simple property or field access: 't => t.MyProperty'. Arg_ParamName_Name'

I think the right way would be:

            builder.OwnsOne(x => x.Author, sa =>
            {
                sa.Property(x => x.UserId).HasConversion(new GuidToStringConverter());  
                sa.HasPartitionKey(x => x.UserId);              
            });

but its not possilble.

How can I solve this problem?

EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.Cosmos 5.0.9)
Target framework: (e.g. .NET 5.0)
Operating system:
IDE: (e.g. Visual Studio 2019 16.10.0)

@ajcvickers ajcvickers added this to the Backlog milestone Aug 17, 2021
@ajcvickers ajcvickers self-assigned this May 8, 2024
@ajcvickers ajcvickers modified the milestones: Backlog, 9.0.0 May 8, 2024
@ajcvickers ajcvickers removed this from the 9.0.0 milestone Jul 1, 2024
@ajcvickers ajcvickers added this to the Backlog milestone Jul 7, 2024
@ajcvickers ajcvickers added the punted-for-9.0 Originally planned for the EF Core 9.0 (EF9) release, but moved out due to resource constraints. label Jul 7, 2024
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
area-cosmos customer-reported punted-for-9.0 Originally planned for the EF Core 9.0 (EF9) release, but moved out due to resource constraints. type-enhancement
Projects
None yet
Development

No branches or pull requests

2 participants