Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cosmos db Hierarchical Partitions in EF Core #28186

Closed
Ntethelelom opened this issue Jun 8, 2022 · 12 comments · Fixed by #33536
Closed

Cosmos db Hierarchical Partitions in EF Core #28186

Ntethelelom opened this issue Jun 8, 2022 · 12 comments · Fixed by #33536
Labels
area-cosmos closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@Ntethelelom
Copy link

Ntethelelom commented Jun 8, 2022

Hi I have a question, when it comes to working with hierarchical partition keys in Entity Framework. The hierarchical partitions are defined in the cosmos database, but I am struggling to work with them in EF when I have to specify HasPartitionKey method. I get an error that my partition specified does not match the partition defined in the document. Please assist on how I can work with hierarchical partitions in EF. See code below:

modelBuilder.Entity(entity =>
{
entity.HasNoDiscriminator();
entity.ToContainer((“Document”));
entity.HasPartitionKey(x => new {x.ClientId , x.ProjectId} );
entity.HasKey(x => new { x.id });
});

Include stack traces

System.ArgumentException: 'The expression 'x => new <>f__AnonymousType1`2(ClientId = x.ClientId, ProjectId = x.ProjectId)' is not a valid member access expression. The expression should represent a simple property or field access: 't => t.MyProperty'. (Parameter 'memberAccessExpression')'

EF Core version: Microsoft.EntityFrameworkCore (6.0.5)
Database provider: Microsoft.EntityFrameworkCore.Cosmos (6.0.5)
Target framework: NET 6.0
IDE: Visual Studio 2022

@CR-CA
Copy link

CR-CA commented Jun 10, 2022

I don't think those functions are suported in Entity Framework.

@smitpatel
Copy link
Contributor

This feature is currently in preview in CosmosDb Sql API.

@Ntethelelom
Copy link
Author

@ajcvickers Do we know when it's going to be released ?

@roji
Copy link
Member

roji commented Jul 19, 2022

This issue is in the Backlog milestone. This means that it is not going to happen for the 7.0 release. We will re-assess the backlog following the 7.0 release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

@umairb-pedal
Copy link

Hi. Where is this in the backlog prioritisation? I assume it won't make it for the 8.0 release?

@ajcvickers
Copy link
Member

@umairb-pedal This issue has zero votes, which, all other things being equal, buts it way down the priority list. Make sure to vote (👍) if its something you need.

@EstherSY
Copy link

EstherSY commented Aug 2, 2023

Hello, is there any workaround to have EF working with the container with hierarchical partition keys? Is there plan for tentative release date for this support?

@ajcvickers
Copy link
Member

This issue is in the Backlog milestone. This means that it is not planned for the next release (EF Core 8.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you.

@vitorlinares
Copy link

I can see this is labeled to be considered for current release, do we have any idea of when that will be released?

@ajcvickers
Copy link
Member

@vitorlinares There is a reasonable chance this will end up in EF9, which ships November 2024.

@vitorlinares
Copy link

Thanks @ajcvickers,
That's helpful for my roadmap planning.
I appreciate the prompt answer.

@aiimi-cclifton
Copy link

Kind of crazy this feature is missing. Just inherited a project using EF Core and cosmos, this prevents you leveraging best practices and if nothing else, should really be added to the docs as an absent feature

Looking forward to its release!

ajcvickers added a commit that referenced this issue Apr 14, 2024
Fixes #28186
Fixes #28265
Fixes #33535

Also:
- Allow non-string partition key values
- Warn if no partition key has been defined
- Use a value converter if needed for values passed to WithPartitionKey (This is probably a bug, but should be docced as a breaking change anyway.)
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 14, 2024
@ajcvickers ajcvickers self-assigned this Apr 14, 2024
@ajcvickers ajcvickers modified the milestones: Backlog, 9.0.0 Apr 14, 2024
ajcvickers added a commit that referenced this issue May 1, 2024
Fixes #28186
Fixes #28265
Fixes #33535

Also:
- Allow non-string partition key values
- Warn if no partition key has been defined
- Use a value converter if needed for values passed to WithPartitionKey (This is probably a bug, but should be docced as a breaking change anyway.)
ajcvickers added a commit that referenced this issue May 1, 2024
Fixes #28186
Fixes #28265
Fixes #33535

Also:
- Allow non-string partition key values
- Warn if no partition key has been defined
- Use a value converter if needed for values passed to WithPartitionKey (This is probably a bug, but should be docced as a breaking change anyway.)

Updated based on review feedback
ajcvickers added a commit that referenced this issue May 2, 2024
* Support hierarchical partition keys in Cosmos provider

Fixes #28186
Fixes #28265
Fixes #33535

Also:
- Allow non-string partition key values
- Warn if no partition key has been defined
- Use a value converter if needed for values passed to WithPartitionKey (This is probably a bug, but should be docced as a breaking change anyway.)

Updated based on review feedback

* Added test for type that cannot be a partition key
@ajcvickers ajcvickers modified the milestones: 9.0.0, 9.0.0-preview5 May 2, 2024
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
@roji roji modified the milestones: 9.0.0-preview5, 9.0.0 Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants