Hi Stef,
I'm trying to project a sequence of items with a related property (object) which in some cases is null.
Having this classes:
public class Item
{
public int Id { get; set; }
public RelatedItem Related { get; set; }
}
public class RelatedItem
{
public string Value { get; set; }
}
Consider this scenario:
var listItem = new List<Item>();
for (int i = 0; i < 100; i++)
{
listItem.Add(new Item
{
Id = i,
Related = i % 2 == 0 ? new RelatedItem{ Value = i % 4 == 0 ? "Related value " + i : null } : null
});
}
var result1 = listItem.Select(i => i.Related?.Value);
var result2 = listItem.AsQueryable().Select("Related.Value");
Result1 works fine and has the expected result (a list of items with Related.Value value or null, in case of Item has Related object assigned or not) but Result2 generates an object reference exception. Is there any way to achieve this?
Thanks!
System.Linq.Dynamic.Core version 1.0.7.6
Hi Stef,
I'm trying to project a sequence of items with a related property (object) which in some cases is null.
Having this classes:
Consider this scenario:
Result1 works fine and has the expected result (a list of items with Related.Value value or null, in case of Item has Related object assigned or not) but Result2 generates an object reference exception. Is there any way to achieve this?
Thanks!
System.Linq.Dynamic.Core version 1.0.7.6