Git Product home page Git Product logo

Comments (12)

ra0o0f avatar ra0o0f commented on May 23, 2024

@drgraduss it's because StringEnumConverter only apply when converting Document object not MyEnum, see the difference:

// result will be 1
JsonConvert.SerializeObject(MyEnum.Value1)
// result will be {"EnumAttribute":"Value1"}
JsonConvert.SerializeObject(new Document { EnumAttribute = MyEnum.Value1 })

move your [JsonConverter(typeof(StringEnumConverter))] attribute on top of enum declartion:

[JsonConverter(typeof(StringEnumConverter))]
    public enum MyEnum
    {
        Value1 = 1,
        Value2 = 2
    }

from arangoclient.net.

drgraduss avatar drgraduss commented on May 23, 2024

Moved JsonConverter declaration to enum with no luck. Still enum @P1 parameter is int.

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 23, 2024

@drgraduss yes i get same result, it's because relinq(library for parsing linq queries) parse enum to its underlying int values before its convertion by json.net. i should look into it

for now you can prevent it by changing your query to this:

db.Query<Document>().Filter(x => x.EnumAttribute == AQL.As<MyEnum>(MyEnum.Value1))

from arangoclient.net.

drgraduss avatar drgraduss commented on May 23, 2024

That worked. Thanks!

PS it looks like every time you're using AQL within query you're getting InvalidOperationException: Aql functions should only be used in ArangoDatabase.Query inside which is caught which affects query construction performance.

Is there a way of pre-compile/cache queries?

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 23, 2024

yes i am aware of exception being thrown, it should be fixed. currently there is no plan for caching/pre- compiling linq queries, but you can always get the translated query data:

var query = db.Query<Document>().Where(x => x.EnumAttribute == MyEnum.Value1).Select(x => x);

                var queryData = query.GetQueryData();
                // and execute it without need for linq query
                db.CreateStatement<Document>(queryData.Query, queryData.BindVars);

from arangoclient.net.

drgraduss avatar drgraduss commented on May 23, 2024

Hey @ra0o0f. I found that you're using custom version of Newtonsoft.Json.

What implications will be if I use standard Newtonsoft.Json instead for documents attributing?

The reason why I need it, I have some model classes in the separate projects that don't have dependency on ArangoDb.Client and I don't want to introduce it.

i.e. my enums used across whole system and are not specific to arango part.

Thanks

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 23, 2024

@drgraduss you should do it by code .if you mean JsonProperty attribute i tried to provide a way to define settings for documents or collections with attributes(declarative way) and code(imperative). you can define your settings by code in a project where ArangoDB.Client is referenced.

// by attribute
[CollectionProperty(CollectionName = "products")]
public class Product 
{
[DocumentProperty(PropertyName = "price")]
    public decimal Price {get; set;}
}

// by code

sharedSetting.Collection.ChangeCollectionPropertyForType<Product>(c =>
                {
                    c.CollectionName = "products";
                });

sharedSetting.Collection.ChangeDocumentPropertyForType<Product>(c => c.Price, d =>
                   {
                       d.PropertyName = "price";
                   });

so there will be no need for JsonProperty, unfortunately not all members of JsonProperty are defined so open an issue for what you else need, i will add them asap.

But if you mean custom JsonConverter like StringEnumConverter, json.net let us add them without attribute usage and i should add a wrapper around it.

let me know if these solve your problem, so i add support for them

from arangoclient.net.

drgraduss avatar drgraduss commented on May 23, 2024

I meant JsonConverter in my case.

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 23, 2024

@drgraduss ok, i will publish new package in 2 days

from arangoclient.net.

drgraduss avatar drgraduss commented on May 23, 2024

@ra0o0f no problem. thanks a lot!

from arangoclient.net.

ra0o0f avatar ra0o0f commented on May 23, 2024

@drgraduss client now has support for custom converters and also a setting for serializing enums, new packages will be uploaded today

examples:

// for add new custom converter
sharedSetting.Serialization.Converters.Add(new StringEnumConverter());

// for enabling enum convertion to strings, this just add `StringEnumConverter` under the hood
sharedSetting.Serialization.SerializeEnumAsInteger = false;

from arangoclient.net.

drgraduss avatar drgraduss commented on May 23, 2024

@ra0o0f Thanks!

from arangoclient.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.