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

Expand property bag definition #22009

Open
Tracked by #240
AndriySvyryd opened this issue Aug 10, 2020 · 3 comments
Open
Tracked by #240

Expand property bag definition #22009

AndriySvyryd opened this issue Aug 10, 2020 · 3 comments

Comments

@AndriySvyryd
Copy link
Member

Look for IDictionary<string, object> implementation or just look for an indexer and ContainsKey() method.

Add Fluent API to configure an ET as a Property bag or not.

@ajcvickers
Copy link
Member

I'm finding it hard to use property bags without this; should we pull it into 5.0?

For example, I thought this would work:

public class ProxyableSharedType
{
    private readonly Dictionary<string, object> _keyValueStore = new Dictionary<string, object>();

    public virtual object this[string key]
    {
        get => _keyValueStore.TryGetValue(key, out var value) ? value : default;
        set => _keyValueStore[key] = value;
    }
}
modelBuilder.SharedTypeEntity<ProxyableSharedType>(
    "PST", b =>
    {
        b.IndexerProperty<int>("Id").ValueGeneratedNever();
        b.IndexerProperty<string>("Payload");
    });

But it doesn't because initially "Id" is not in the dictionary, so null is returned by the indexer, but the property doesn't support nulls.

@ajcvickers ajcvickers removed this from the Backlog milestone Aug 26, 2020
@smitpatel
Copy link
Member

Should property getter for indexer property account for the fact that object is returned from indexer (which could be null) and convert it to appropriate CLR default?

@ajcvickers
Copy link
Member

@smitpatel Possibly; I can look at making it act like a nulable backing field.

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