Comments (12)
@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.
Moved JsonConverter
declaration to enum with no luck. Still enum @P1
parameter is int.
from arangoclient.net.
@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.
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.
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.
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.
@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.
I meant JsonConverter
in my case.
from arangoclient.net.
@drgraduss ok, i will publish new package in 2 days
from arangoclient.net.
@ra0o0f no problem. thanks a lot!
from arangoclient.net.
@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.
@ra0o0f Thanks!
from arangoclient.net.
Related Issues (20)
- ArangoServerException not throw when db unavailable HOT 2
- Thread safety HOT 7
- Confused with SystemDatabaseCredential HOT 5
- Custom Index HOT 6
- ByExampleAsync missing HOT 2
- Make ChangeCollectionPropertyForType public HOT 1
- Using LINQ query with Where performance HOT 1
- Error in generated AQL when upserting a generic document HOT 7
- ArangoServerException eats up all the useful information like status code and error number HOT 2
- Make collection name resolver more extensible HOT 2
- Annotating a property of type Guid as DocumentProperty.Key throws InvalidCastException HOT 2
- Support private setter
- CreateStatement<object> & Remove Vertex HOT 1
- Ternary operator support
- Global error handling policy
- Support for keyOptions: uuid
- Edge Document API not supported?
- Cannot Simply Connect to Server...... HOT 2
- Secure connection to ArangoDB
- Query directly within a collection
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arangoclient.net.