[CSHARP-2487] Does string field definition should match model filed name or document field name? Created: 22/Jan/19 Updated: 27/Oct/23 Resolved: 28/Jan/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Mikhail Bolshakov | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Hi. FilterDefinitionBuilder could accept string as first parameter for all of their method. Like this:
Does this field should match property name of my model or it should match field name from document? My issue that filter definition renders inproper query for date field if provided field name string doesnt match my model property name exactly. In following example "dateOfBirth" doesn't mapped to model field Employee.DateOfBirth
And this filter doesn't work. But if we will provide field name like "DateOfBirth" it will be mapped:
I found a place where this behaviour could be changed but I'm not sure if it's a bug. |
| Comments |
| Comment by Robert Stam [ 28/Jan/19 ] | |
|
The field name you pass to Filter.Eq should match the name of the property in your C# class. If you pass a field name to Filter.Eq that does not match any property of your C# class then Filter.Eq simply uses that field name verbatim and serializes the value using a serializer from the serializer registry. I realize this might seem odd, but there are at least two reasons for this:
So just be sure to match the name of your C# class exactly (i.e. use "DateOfBirth" instead of "dateOfBirth"). You could also consider using the type safe version of Filter.Eq:
|