Dynamic Select with respecting to object hierarchy (To not flatten the object)
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
Try,
products.Select("new Product(Price, new(Category.Name) As Category))");
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