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

Dynamic Select with respecting to object hierarchy (To not flatten the object)

Open mohsenno1 opened this issue 7 years ago • 2 comments

I'm using the library in .Net Core. It's working perfect. Except one thing that I need. When you use the Dynamic select, it flatten the object. Is there any way to select the object in its their original position? Let me explain this with an example Suppose that we have two objects:

public class Category {
    public int? Id { get; set; }
    public string Name { get; set; }
}

public class Product {
    public int? Id { get; set; }
    public string Name { get; set; }
    public double Price { get; set; }
    public Category Category { get; set; }
}

now when I try to Select the Category.Name of the Product it's placed in the place of the Product.Name and not Product.Category.Name. I'm using:

products.Select("new Product(Price, Category.Name)");

the result is as follows:

{
      "Id": null,
      "Name": "A Category Name",
      "Price": 1234,
      "Category": null
}

but what I expect to have is:

{
      "Id": null,
      "Name": null,
      "Price": 1234,
      "Category": {
          "Id": null,
          "Name": "A Category Name"
      }
}

Can anybody tell me is there a way to accomplish this? Or is it possible to do this with this library at all?

Thank you

mohsenno1 avatar Sep 13 '19 09:09 mohsenno1

Try, products.Select("new Product(Price, new(Category.Name) As Category))");

Juliete avatar Oct 31 '19 15:10 Juliete

Hello @mohsenno1

I will close this issue as @Juliete provided an answer so we will assume everything is working.

If you still have an issue and can reproduce it in a standalone project, we will be happy to re-open and investigate it.

Best Regards,

Jon


Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework Extensions • Entity Framework Classic • Bulk Operations • Dapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval Function • SQL Eval Function

JonathanMagnan avatar May 09 '20 14:05 JonathanMagnan