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

Converting values to primitive types in primitive collections #30893

Closed
frankbuckley opened this issue May 15, 2023 · 2 comments
Closed

Converting values to primitive types in primitive collections #30893

frankbuckley opened this issue May 15, 2023 · 2 comments

Comments

@frankbuckley
Copy link

May be related to #25343 and possibly covered by #30677.

The work on primitive collections now enables:

public class Article
{
    public IList<string> Keywords { get; }
}

// Maps to JSON string array in text column and facilitates querying
builder.Property(e => e.Keywords);

Which is super helpful!

However, it does not appear to be possible to configure a value converter to provide a conversion to a primitive type to be stored as a primitive collection - for example:

public class Article
{
    public IList<Tag> Tags{ get; }
}

// Does not work: System.InvalidCastException : Unable to cast object of type 'System.Linq.Expressions.Expression1`1[System.Func`2[System.Object,System.String]]' to type 'System.Linq.Expressions.Expression`1[System.Func`2[System.Collections.Generic.IEnumerable`1[System.String],System.String]]'.
builder.Property(e => e.Tags).HasConversion(new TagListToStringEnumerableConverter());

While we can already use something like a TagListToJsonStringConverter today, that does not enable the primitive collections query enhancements.

Might something like this might be supported?

@roji
Copy link
Member

roji commented May 16, 2023

@frankbuckley this should be possible by configuring a value converter on the element of the primitive collection, rather than on the collection itself. We're currently lacking APIs to configure anything on the element (e.g. store type, requiredness), but this is definitely something that's planned for 8.0. The tracking issue for that is #30730 (I've added a note there to test this).

@roji
Copy link
Member

roji commented May 16, 2023

Duplicate of #30730

@roji roji marked this as a duplicate of #30730 May 16, 2023
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants