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

Arango db field casing issue with linq queries #39

Closed
adamlubek opened this issue Feb 10, 2016 · 4 comments
Closed

Arango db field casing issue with linq queries #39

adamlubek opened this issue Feb 10, 2016 · 4 comments

Comments

@adamlubek
Copy link

hey, first of all, thanks for cool library :)

Down to business: in arango, I've got Person collection with last name fields (notice second object's field starts with lower case):
[{"LastName":"a"},{"lastName":"b"},{"LastName":"c"}]

In C#, I've got Person class with LastName field.

public class Person
{
    public string LastName;
}

Now, db.Query().ToList() returns all 3 objects with LastName properly initialized with respective values. However, linq query db.Query().Where(e => AQL.Contains(e.LastName, "b")).ToList() doesn't return anything. I'm guessing this is not intentional?

@ra0o0f
Copy link
Owner

ra0o0f commented Feb 10, 2016

the reason that db.Query().ToList() returns the lastName(with the lower l) member is because json.net deserialize object members if it's camelcased in the json(in your case lastName is camelcase of LastName). but this behavior is not at serializing objects( AQL.Contains(e.LastName, "b") will translate to aql syntax contains(e.LastName,"b") ).

lastName & LastName are two different document members for the ArangoDB database. you could have both of them in an object. did you load Person collection with import tools? if yes try to validate the member names before inserting them(.net client also has a method for import, db.Advanced.BulkImport which is not in nuget package yet)

also there are helper methods in .net client that you can override member name resolving( which does not solve your problem, you should rename lastName & LastName fields to one thing)

                sharedSetting.Collection.ChangeCollectionPropertyForType<Person>(x =>
                {
                    // will resolve all collection members name from PascalCase(c#) to camelcase(ArangoDB)
                    x.Naming = NamingConvention.ToCamelCase;
                });

                sharedSetting.Collection.ChangeDocumentPropertyForType<Person>(x => x.LastName, (p) =>
                {
                    // set the name for just one member
                    p.PropertyName = "lastName";

                    // naming convection for just one member
                    p.Naming = NamingConvention.ToCamelCase;
                });

@adamlubek
Copy link
Author

thanks for prompt and detailed response. However, I hope that you see why I find this confusing. From my perspective it would be better if this behavior was more consistent i.e. either arango lastName wouldn't be mapped to LastName in C# while using db.Query().ToList() or if field content was included while using db.Query().Where(e => AQL.Contains(e.LastName, "b")).ToList()

@ra0o0f
Copy link
Owner

ra0o0f commented Feb 11, 2016

you're right, the resolving names should be consistent either in serializing/serializing, i wont close the issue for now.

@ra0o0f
Copy link
Owner

ra0o0f commented Feb 22, 2016

@adamlubek about consistent member name resolving, json.net behaves First attempts to get an exact case match of propertyName and then a case insensitive match according to http://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json_Serialization_JsonPropertyCollection_GetClosestMatchProperty.htm

@ra0o0f ra0o0f closed this as completed Mar 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants