[CSHARP-1998] UpdateDefinitionBuilder fails when updating enumerable field type with "object" Created: 12/Jun/17 Updated: 07/Feb/22 Resolved: 07/Feb/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq |
| Affects Version/s: | 2.4.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Martin Lobger | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 2 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows |
||
| Attachments: |
|
| Epic Link: | CSHARP-3615 |
| Description |
|
When using UpdateDefinitionBuilder<> to update field parsing in an anonymous type as "object", it will fail to update the field correctly - introducing _t and _v. This issue relates to Attached is Program.cs that exposes this issue.
|
| Comments |
| Comment by James Kovacs [ 07/Feb/22 ] |
|
This works correctly on recent versions of the driver. Please open a new ticket with a complete repro if UpdateBuilder<T>.Set is not working as expected. |
| Comment by Svetoslav Milenov [ 30/Oct/17 ] |
|
The issue is bigger than this or It appears, that UpdateBuilder<T>.Set("someprop", someValue) stores the value as String, b/c it infers the type from the field provided, i.e. it does .Set<string>("someprop", value.ToString()). At least that what my tests show when using even simple filed of type IEnumerable<string>. The same problem exists, if using a more generic property expression, like Expression<Func<T, object>> instead of a strictly typed expression Expression<Func<T, IEnumerable<string>>. As far as FieldDefinition<T> is used to represent the field, I think that the proper behavior (as T is known) is to interrogate the class type, and use the property type instead of that's supplied in the Set method field generic type param. My concrete use scenario is to have a list of Expression<Func<T, object>> to update any number of properties, without exposing mongo internals outside the repository. I.e. I have a generic repository like IRepository<T>, and update method Update(T resource, IEnumerable<Expression<Func<T,object>>> propsToUpdate). |