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

Created on 21 Feb 2019  路  9Comments  路  Source: dotnet/efcore

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.

area-cosmos punted-for-3.0 type-enhancement

Most helpful comment

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.

All 9 comments

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

@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.

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.

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

@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.

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.

@Assassinbeast
something like

modelBuilder.Entity<YourEntity>()
        .Property(e => e.Strings)
        .HasConversion(
            v => string.Join(',', v),
            v => v.Split(',', StringSplitOptions.RemoveEmptyEntries));
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?

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.

Was this page helpful?
0 / 5 - 0 ratings