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

Dynamic properties not supported #217

Open
smurfpandey opened this issue May 17, 2015 · 3 comments
Open

Dynamic properties not supported #217

smurfpandey opened this issue May 17, 2015 · 3 comments

Comments

@smurfpandey
Copy link

I am trying to insert an object with dynamic property. But the code hangs at insert. I also tried replacing dynamic with JObject, but then, only id is getting inserted.

Object definition

public class Banana
    {

        [DataMember(Name = "id", EmitDefaultValue = false)]
        public Guid Id { get; set; }

        public dynamic flesh { get; set; }
    }

Code to Insert

public static async Task<string> PlantBanana(Banana objBanana)
        {
            string firstError = string.Empty;            
            using (IConnection conn = connectionFactory.Get())
            {
                var response = await conn.RunAsync(Banana.Table.Insert(objBanana));

                if (response.Errors > 0)
                {
                    firstError = response.FirstError;
                    return firstError;
                }                
            }

            return firstError;
        }

I am using Newtonsoft serializer.

@mfenniak
Copy link
Owner

Hey @smurfpandey. Thanks for the bug report; neither of the object serializers in rethinkdb-net currently support using dynamic properties or fields. But, our recently added support for key-value dictionaries might have laid the groundwork for this to be feasible... I will take a look into it and see what it would take to implement.

@mfenniak
Copy link
Owner

Hrm, there are limitations on the capabilities of dynamic with expression trees that seem like they would prevent rethinkdb-net from using them in any serious way. Nothing with a dynamic type can be used in any way inside of an expression tree, and, we use expression trees to convert C# logic into RethinkDB logic.

Take your example of a Banana class, and then try adding a query filter.

var response = await conn.RunAsync(Banana.Table.Filter(b => b.flesh > 100));

This will come up with a compiler error, error CS1963: An expression tree cannot contain a dynamic operation. If the compiler can't support this then we couldn't either, unless we introduced a whole new, non-type-safe mechanism to construct RethinkDB queries. I'm not sure that'd be worth the effort.

Is there a specific use-case that you had in mind for dynamic? I think I could support it as a return value, but, not as a value that can be interacted with in a query in any way.

@smurfpandey
Copy link
Author

@mfenniak I am working on a simple mock server which will output JSON response. That's why I am using the dynamic flesh property to hold the JSON provided by the user. Since this mock server should accept any kind of valid JSON, I am using dynamic. Anyways, I replaced rethinkdb with arangodb, and got it working with it's .net driver. But the interesting part was, dynamic was not working there either, but that driver supports JSON string as input, so I serialized my object then stored it, same thing during fetching, serialize the output, then again deserialize as my Banana object.

You can check what i did here: https://github.com/smurfpandey/api-monkey/blob/master/APIMonkey/Code/DataManager.cs
Driver I am using: https://github.com/yojimbo87/ArangoDB-NET

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