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: Add basic support for collections and dictionaries of primitive types #14762

Closed
AndriySvyryd opened this issue Feb 21, 2019 · 20 comments · Fixed by #25344
Closed

Cosmos: Add basic support for collections and dictionaries of primitive types #14762

AndriySvyryd opened this issue Feb 21, 2019 · 20 comments · Fixed by #25344
Labels
area-cosmos closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-3.0 type-enhancement
Milestone

Comments

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Feb 21, 2019

It should be possible to implement this without a ValueConverter because Cosmos supports them natively.

This issue doesn't include server translation of queries with any methods using properties of these types, essentially they will be treated as atomic units.

@AndriySvyryd AndriySvyryd changed the title Cosmos: Add support for collections and dictionaries of primitive types Cosmos: Add basic support for collections and dictionaries of primitive types Feb 21, 2019
@ajcvickers ajcvickers added this to the 3.0.0 milestone Feb 22, 2019
@smitpatel smitpatel mentioned this issue Feb 22, 2019
82 tasks
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog May 10, 2019
@kierenj
Copy link

kierenj commented Sep 18, 2019

Hi, I'm keen to understand the propose-punt label please? I understand Backlog means this is vaguely planned for the future. Am keen to see if a project in 3-6 months should go the EF Core / Cosmos route or not - understand you can't give a definitive on this feature but just so I can guess the odds :) Thanks

@smitpatel
Copy link
Member

@kierenj - We use propose-punt label for issues which we had planned for certain release but due to time constraints we ended up removing it from that release. Like this issue was planned for 3.0 but we had more work in 3.0 then what can be done in the time we got. So propose-punt label signifies that we consider this should be punted from 3.0 release. We go through such issues and decide if we can punt past 3.0 or we need to do it in 3.0. This issue got cut and propose-punt became punted-for-3.0.

This issue is currently in backlog milestone so we are not working on it for our next release 3.1. Cosmos being a new provider which is going to be RTM first time in 3.0, we are going to evolve cosmos based on user feedback. We will prioritize adding features which are requested by many customers. When planning a release, we look at how many people have voted for a feature to decide if it is in demand. Please upvote first issue if you need this.

@svrooij
Copy link

svrooij commented Nov 13, 2020

It seems weird to me that the provided documentation states how easy it is to embed entities, that I couldn't believe that embedding a simple string collection is unsupported.

@ajcvickers or @smitpatel do you guys maybe have an update for us? Since EF Core 5 is just released and this still isn't supported.

@kierenj
Copy link

kierenj commented Nov 13, 2020

@svrooij Strings aren't entities, of course. I think the documentation is accurate

@svrooij
Copy link

svrooij commented Nov 13, 2020

@svrooij Strings aren't entities, of course. I think the documentation is accurate

Yes, if you put it that way, sure. But I wasn't talking about the documentation, I was talking about that it's weird you're able to embed entire objects but not a collection of strings. Even more because cosmos supports the ARRAY_CONTAINS query function.

So if I stop using the EF core framework and just connect to plain cosmos I can set a property to a string collection and even use ARRAY_CONTAINS to query based on the values.

@Assassinbeast
Copy link

It should be possible to implement this without a ValueConverter because Cosmos supports them natively.

@AndriySvyryd can you show an example on how to do it with a ValueConverter? I would really appreciate it.

@Marusyk
Copy link
Member

Marusyk commented Nov 22, 2020

@Assassinbeast
something like

modelBuilder.Entity<YourEntity>()
        .Property(e => e.Strings)
        .HasConversion(
            v => string.Join(',', v),
            v => v.Split(',', StringSplitOptions.RemoveEmptyEntries));

@Assassinbeast
Copy link

Assassinbeast commented Nov 22, 2020

modelBuilder.Entity<YourEntity>()
        .Property(e => e.Strings)
        .HasConversion(
            v => string.Join(',', v),
            v => v.Split(',', StringSplitOptions.RemoveEmptyEntries));

@Marusyk Thanks! So this will mean in my C# code, that its a string array, but in CosmosDB, it will become a single string. That means I cant make a CosmosDB query against an array. Is that correct?

@svrooij
Copy link

svrooij commented Nov 22, 2020

That means I cant make a CosmosDB query against an array. Is that correct?

That is exactly the problem. This way it is saved but you cannot query for it.

@Drew-E
Copy link

Drew-E commented Feb 25, 2021

Is there any update on this? It definitely missed 5.0 as well.

@AndriySvyryd
Copy link
Member Author

@Drew-E It's in the Backlog milestone, meaning it's not planned for 6.0 either

@pcbl
Copy link

pcbl commented Feb 28, 2021

Hi Folks,

Facing same issue. Just need to save an double[], but using the folowing code:

location.Property(l => l.Coordinates).HasConversion(t => JsonConvert.SerializeObject(t),
                                             s => JsonConvert.DeserializeObject<double[]>(s)).ToJsonProperty("coordinates");

It gets saved as:

"coordinates": "[-44.431451,-16.223516]"

But I expect:

"coordinates": [-44.431451,-16.223516]

This EF Core Cosmos useless on my case as I need to run Spatial Queries against the data. Quite annoying to see that this issue is open for so long, but still not in place.

That way I am forced to use CosmosDB SDK directly, which I wanted to avoid on this specific scenario...

Are there any workaround I could make to overcome this issue until there`s a fix for it? Tried many options, but none worked... (Actually, there is, check next "Edit/Update")..

Edit/Update
A Possible workaround is to use the "__jObject" shadow property over the EF Entry... more info on:
https://docs.microsoft.com/en-us/ef/core/providers/cosmos/unstructured-data

By doing that you are actually manipulating the real json which will be persisted on cosmos. As the MSDN mentions, that should be a last resort... So far that is the only way I managed to save the array as expected... on my case as a double[]...

@AndriySvyryd
Copy link
Member Author

@pcbl Spatial support is tracked by #17317

@pcbl
Copy link

pcbl commented Mar 1, 2021

Thanks for the Heads up, @AndriySvyryd !
As far as I could see, this feature is on the backlog and might come sometime in the future. Or do you have any information about when it could be available?

@AndriySvyryd
Copy link
Member Author

For issues in the backlog we don't have any specific plans, they are reprioritized after each release.

@PaulOst
Copy link

PaulOst commented Mar 8, 2021

Is first-class support for collections and dictionaries of primitive types anywhere in our future? Why is such a basic capability in the backlog for so long? Not having this capability is a showstopper for my team. Whatever your reprioritization plans are you are giving us the impression that the EF Core provider just isn't important.

@ghost
Copy link

ghost commented Mar 8, 2021 via email

@pcbl
Copy link

pcbl commented Mar 8, 2021

@ericb-blankenburg , @PaulOst ,
On my Team we end up not using EF Core for the objects we store on Cosmos and relies on stuff like GeoSpatial data and so on. For Collections and Dictionaries we did not notice the issue as on the case in question it was a simple object with coordinates. At the end of the day we implemented a repository using CosmosDB SDK directly... For now our CosmoDB repository is somehow very limited as we hope to switch it to the EF Core version later down the road... But when that will be? Not so sure.. :-)

@Drew-E
Copy link

Drew-E commented Mar 9, 2021

Yes, there are workarounds. We could modify our document structure to use a list of objects with a single property. We can use the Cosmos SDK instead of EF Core. But really, this is such a basic feature that it should be supported by EF Core.

Why such a low priority on supporting this? Are there not enough people that require it? Is the effort too large? Is every backlog item ahead of this one really a higher priority? A little transparency would be great.

@AndriySvyryd
Copy link
Member Author

AndriySvyryd commented Mar 9, 2021

You can read about our planning process, based on it we came up with the following plan. It does have Cosmos database provider in it, but the details haven't been decided as it depends on the progress of other features in the plan. As soon as the team members that can work on Cosmos finish their assigned committed features we will update the plan.

You can see exactly what we are currently working on in the biweekly updates.

@ajcvickers ajcvickers modified the milestones: Backlog, 6.0.0 May 6, 2021
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 27, 2021
@AndriySvyryd AndriySvyryd removed their assignment Jul 27, 2021
@ghost ghost closed this as completed in #25344 Jul 28, 2021
ghost pushed a commit that referenced this issue Jul 28, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-rc1 Aug 12, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-rc1, 6.0.0 Nov 8, 2021
This issue was closed.
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. punted-for-3.0 type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants