System.Linq.Dynamic.Core icon indicating copy to clipboard operation
System.Linq.Dynamic.Core copied to clipboard

Single nested object unwraps into parent

Open penumbra23 opened this issue 4 years ago • 0 comments

Hi everyone! 👋

First of excellent library helped me very much in my projects!

I have an issue that should be easy to solve, but I can't find any solution... I'm using the latest version so far and the in-memory SQL package.

Description

When having a class with a property of another class type, the child object unwraps instead of leaving as it is. For example,

class Person {
    public string Name { get; set; }
    public Vehicle Vehicle { get; set; }
}

class Vehicle {
    public string Manuf { get; set; }
}
...
var query = context.Persons.Select("Name, Vehicle.Select(new { Manuf } as Car)")

throws Unhandled exception. No property or field 'Manuf' exists in type 'Person'

And this var query = context.Persons.Select("Name, Vehicle.Manuf as Car)") unwraps the Vehicle inside the Person object, so I get Manuf inside of Person

But this var query = context.Persons.Select("Name, Vehicle as Car)") returns fine with the Vehicle object nested inside the Car prop.

Fiddle or Project

Here is an example with Customer and Address https://dotnetfiddle.net/FO1vuS

Any ideas why and how to get the expected result of Vehicle nested inside Person?

penumbra23 avatar Sep 24 '21 16:09 penumbra23