Skip to content

Expressions on dynamic objects #136

@NickDarvey

Description

@NickDarvey

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 ExpandoObjects from a JSON payload deserialized by Json.NET. I see you have a test for JObjects 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.

//[Fact]
public void ExpressionTests_Select_ExpandoObjects()
{
    //Arrange
    dynamic a = new ExpandoObject();
    a.Name = "a";
    a.BlogId = 100;
    dynamic b = new ExpandoObject();
    b.Name = "b";
    b.BlogId = 100;
    var list = new List<dynamic> { a, b };
    IQueryable qry = list.AsQueryable();

    var result = qry.Select("it").Select("BlogId");

    //Assert
    Assert.Equal(new[] { 100, 200 }, result.ToDynamicArray<int>());
}

Expected

Passes.

Actual

It's commented out. It fails when running it:

Message: System.Linq.Dynamic.Core.Exceptions.ParseException : No property or field 'BlogId' exists in type 'Object'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions