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] Support collections of scalar types #4179

Closed
Tracked by #30731
Chiliyago opened this issue Dec 26, 2015 · 8 comments
Closed
Tracked by #30731

[Cosmos] Support collections of scalar types #4179

Chiliyago opened this issue Dec 26, 2015 · 8 comments
Labels
area-cosmos area-o/c-mapping area-primitive-collections closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@Chiliyago
Copy link

An entity class with a property of List or ICollection of Int does not work.

public class Foo
 {
     public ICollection<int> RowValues { get; set; }
     public ICollection<int> ColValues { get; set; }
 }

Here is the error message.
The property 'RowValues' on entity type 'Models.Foo' has not been added to the model or ignored.

Is this a bug or am I doing this wrong?

Thanks

@rowanmiller
Copy link
Contributor

EF doesn't support storing collections of scalar types. The best workaround at the moment would be to add [NotMapped] to those properties and then have another property that wraps the ICollection<int> represents the serialized for of the data (such a comma-separated string). Then let EF map to that property.

@rowanmiller rowanmiller changed the title EF7 not handling List<int> entity propery Support collections of scalar types Jan 12, 2016
@rowanmiller rowanmiller added this to the Backlog milestone Jan 12, 2016
@bjorn-ali-goransson
Copy link

Any tips on how I could configure EF Core to always map IEnumerable<int> to string and the value stored to DB will be its JSON representation?

I.e. custom mapping, serializing and parsing based on type (that is, general - not based on property per se).

@ajcvickers ajcvickers changed the title Support collections of scalar types Value converter for collections of scalar types to some string notation May 17, 2018
@ajcvickers ajcvickers added size~1-day help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. labels May 17, 2018
@ajcvickers ajcvickers self-assigned this May 17, 2018
@ajcvickers ajcvickers modified the milestones: Backlog, 3.0.0 May 17, 2018
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Aug 3, 2018
@ajcvickers ajcvickers changed the title Value converter for collections of scalar types to some string notation Support collections of scalar types Dec 17, 2018
@ajcvickers
Copy link
Member

Note: there are two potential approaches to solving this problem:

  • Using a value converter to serialize all the values into a single column
  • Mapping to a table which contains the values and collapsing that mapping down to the IEnumerable/ICollection property on the entity. (See OwnsMany primitive type support? #14115)

We may choose to implement either one or both of these. The first can be done manually without mich code using a custom value converter. For example:

modelBuilder
    .Entity<User>()
    .Property(e => e.Roles)
    .HasConversion(
        v => string.Join(',', v),
        v => v.Split(',', StringSplitOptions.None));

(Note that this is a naive serialization that doesn't account for the separator character being included in some of the values, but using something more robust, such as JSON serialization, is just a matter of plugging in the right serialization code.)

@roji
Copy link
Member

roji commented Mar 30, 2023

#29427 already tracks mapping primitive collections to JSON columns, whereas #25163 tracks mapping primitive collections to a separate table. Is this issue needed (though it's a ancient 4-digit issue which deserves respect!)

@roji roji removed this from the Backlog milestone Mar 30, 2023
@ajcvickers ajcvickers changed the title Support collections of scalar types Support collections of scalar types on Cosmos Apr 13, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0-preview4, Backlog Apr 13, 2023
@ajcvickers ajcvickers removed their assignment Apr 13, 2023
@roji roji changed the title Support collections of scalar types on Cosmos [Cosmos] Support collections of scalar types Apr 18, 2023
@roji roji mentioned this issue Apr 19, 2023
34 tasks
ajcvickers added a commit that referenced this issue Apr 2, 2024
This change starts using the EF8 primitive collection infrastructure for primitive collections in Cosmos. This involves adding support for nested collections and read-only collections.

The main challenge here is supporting all the different collection types when, for example, `List<List<string>>` cannot be cast to `IEnumerable<IEnumerable<string>>`. To support this, we use exact collection types in snapshots, and we use non-generic methods in the nested comparers and serializers.

General dictionary mapping still not supported.
No extensive query testing done yet.

Model building and change tracking for #30713
Fixes #25364
Fixes #25343
Part of #4179
Fixes #31722
@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 2, 2024
@ajcvickers ajcvickers modified the milestones: Backlog, 9.0.0 Apr 2, 2024
@ajcvickers ajcvickers self-assigned this Apr 2, 2024
ajcvickers added a commit that referenced this issue Apr 3, 2024
This change starts using the EF8 primitive collection infrastructure for primitive collections in Cosmos. This involves adding support for nested collections and read-only collections.

The main challenge here is supporting all the different collection types when, for example, `List<List<string>>` cannot be cast to `IEnumerable<IEnumerable<string>>`. To support this, we use exact collection types in snapshots, and we use non-generic methods in the nested comparers and serializers.

General dictionary mapping still not supported.
No extensive query testing done yet.

Model building and change tracking for #30713
Fixes #25364
Fixes #25343
Part of #4179
Fixes #31722
ajcvickers added a commit that referenced this issue Apr 3, 2024
* Consolidate primitive collections across relational and Cosmos

This change starts using the EF8 primitive collection infrastructure for primitive collections in Cosmos. This involves adding support for nested collections and read-only collections.

The main challenge here is supporting all the different collection types when, for example, `List<List<string>>` cannot be cast to `IEnumerable<IEnumerable<string>>`. To support this, we use exact collection types in snapshots, and we use non-generic methods in the nested comparers and serializers.

General dictionary mapping still not supported.
No extensive query testing done yet.

Model building and change tracking for #30713
Fixes #25364
Fixes #25343
Part of #4179
Fixes #31722

* Remove dead files

* Updates based on review feedback
@ajcvickers ajcvickers modified the milestones: 9.0.0, 9.0.0-preview4 Apr 8, 2024
@ajcvickers ajcvickers removed their assignment Sep 1, 2024
@roji roji modified the milestones: 9.0.0-preview4, 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 area-o/c-mapping area-primitive-collections closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

10 participants