-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
Expressions on dynamic objects #136
Comments
Also related to #132 |
A possible solution could be that a new class is defined in this library which keeps the information about the properties. So prototype code would be: var property1 = new DynamicProperty("BlogId", typeof(int));
var property2 = new DynamicProperty("Name", typeof(string));
var a = new DynamicObject(property1, property2);
a.Name = "a";
a.BlogId = 100;
var list = new List<dynamic> { a, a };
IQueryable qry = list.AsQueryable();
var result = qry.Select("it").Select("BlogId"); // At this point the library should understand that the objects special.
// Maybe update the interface so that the type-information is also added?
// like:
var result = qry.Select(new [ property1, property2 ], "it").Select("BlogId"); |
Hello @NickDarvey and @jogibear9988, I've written some code which I use in WireMock.net which generated a select string based on a And works like: // Assign
var j = new JObject
{
{"U", new JValue(new Uri("http://localhost:80/abc?a=5"))},
{"N", new JValue((object) null)},
{"G", new JValue(Guid.NewGuid())},
{"Flt", new JValue(10.0f)},
{"Dbl", new JValue(Math.PI)},
{"Check", new JValue(true)},
{"Items", new JArray(new[] {new JValue(4), new JValue(8)})},
{
"Child", new JObject
{
{"ChildId", new JValue(4)},
{"ChildDateTime", new JValue(new DateTime(2018, 2, 17))},
{"TS", new JValue(TimeSpan.FromMilliseconds(999))}
}
},
{"Id", new JValue(9)},
{"Name", new JValue("Test")}
};
// Act
string line = JsonUtils.GenerateDynamicLinqStatement(j);
// Assert
var queryable = new[] {j}.AsQueryable().Select(line);
bool result = queryable.Any("Id > 4");
Check.That(result).IsTrue();
Check.That(line).IsEqualTo("new (Uri(U) as U, null as N, Guid(G) as G, double(Flt) as Flt, double(Dbl) as Dbl, bool(Check) as Check, (new [] { int(Items[0]), int(Items[1])}) as Items, new (int(Child.ChildId) as ChildId, DateTime(Child.ChildDateTime) as ChildDateTime, TimeSpan(Child.TS) as TS) as Child, int(Id) as Id, string(Name) as Name)"); This could be a solution for your problem? |
Hi,
I'm wondering what the story is for
System.Linq.Dynamic.Core
and types that aren't known till runtime. Is this supported right now, and if it's not, will it be one day?Right now, I have an
IEnumerable<dynamic>
I can that I'd like to query. Is there any way I can compose a query on top of that? Is there any other way you know of for handling this case?(The collection contains
ExpandoObject
s from a JSON payload deserialized by Json.NET. I see you have a test forJObjects
but we don't want to be bound to that type as we may have multiple serializers.)There is a test in there for verifying a
Select
on a collection of dynamic objects, but it's disabled right now.Repro
Run this test.
Expected
Passes.
Actual
It's commented out. It fails when running it:
The text was updated successfully, but these errors were encountered: