We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When patching a dictionary with a value from a property instead of a value in a variable a InvalidCastException or NotSupportedException is thrown.
InvalidCastException
NotSupportedException
// ✅ [RavenTheory(RavenTestCategory.ClientApi | RavenTestCategory.Patching)] [RavenData(DatabaseMode = RavenDatabaseMode.All)] public void PatchOnDictionaryShouldWork(Options options) { using (var store = GetDocumentStore(options)) { string id; using (var session = store.OpenSession()) { var entity = new Foo { Dict = new() }; session.Store(entity); session.SaveChanges(); id = session.Advanced.GetDocumentId(entity); } var key = "key"; using (var session = store.OpenSession()) { session.Advanced.Patch<Foo, string>(id, x => x.Dict[key], string.Empty); session.SaveChanges(); Assert.Equal(string.Empty, session.Load<Foo>(id).Dict[key]); } } } // ❌ System.InvalidCastException : Unable to cast object of type 'System.Linq.Expressions.FieldExpression' to type 'System.Linq.Expressions.ConstantExpression'. [RavenTheory(RavenTestCategory.ClientApi | RavenTestCategory.Patching)] [RavenData(DatabaseMode = RavenDatabaseMode.All)] public void PatchOnDictionaryWithAnonymousPropertyShouldWork(Options options) { using (var store = GetDocumentStore(options)) { string id; using (var session = store.OpenSession()) { var entity = new Foo { Dict = new(), }; session.Store(entity); session.SaveChanges(); id = session.Advanced.GetDocumentId(entity); } var request = new { Key = "key" }; using (var session = store.OpenSession()) { session.Advanced.Patch<Foo, string>(id, x => x.Dict[request.Key], string.Empty); session.SaveChanges(); Assert.Equal(string.Empty, session.Load<Foo>(id).Dict[request.Key]); } } } // ❌ System.NotSupportedException : The used constant value is not supported: `value(FastTests.Client.Documents.Patch+FooRequest)` (FooRequest) [RavenTheory(RavenTestCategory.ClientApi | RavenTestCategory.Patching)] [RavenData(DatabaseMode = RavenDatabaseMode.All)] public void PatchOnDictionaryWithTypePropertyShouldWork(Options options) { using (var store = GetDocumentStore(options)) { string id; using (var session = store.OpenSession()) { var entity = new Foo { Dict = new(), }; session.Store(entity); session.SaveChanges(); id = session.Advanced.GetDocumentId(entity); } var request = new FooRequest { Key = "key" }; using (var session = store.OpenSession()) { session.Advanced.Patch<Foo, string>(id, x => x.Dict[request.Key], string.Empty); session.SaveChanges(); Assert.Equal(string.Empty, session.Load<Foo>(id).Dict[request.Key]); } } } public class Foo { public Dictionary<string, string> Dict { get; set; } } public class FooRequest { public string Key { get; set; } }
The text was updated successfully, but these errors were encountered:
Hi, thanks for the tests. I've created a ticket for it: https://issues.hibernatingrhinos.com/issue/RavenDB-22347/Unable-to-patch-dictionary-with-a-property
Sorry, something went wrong.
No branches or pull requests
When patching a dictionary with a value from a property instead of a value in a variable a
InvalidCastException
orNotSupportedException
is thrown.The text was updated successfully, but these errors were encountered: