Hello,
I dynamically add columns to my RadzenTable
And I have a question regarding filling in the Field property on a Column item.
This is my field property of my Column object:
Field = (x => x.MyList.FirstOrDefault(c => c.MyItem.Id == Id).MyProp),
I would like to do null checks on this since whenever I run my app and it doesn't find that Id it will crash with a null reference since it can't get the MyProp from that Item.
So I tried this,
Field = (x => x.MyList.FirstOrDefault(c => c.MyItem.Id == Id)?.MyProp),
but you can't do this since:
CS8072 - An expression tree lambda may not contain a null propagating operator.
I then looked a bit further on the internet and tried to do this which doesn't give errors on a build:
Field = (x => x.MyList.FirstOrDefault(c => c.MyItem.Id == Id) == null ?
x.MyList.FirstOrDefault(c => c.MyItem.Id == Id).MyProp : "")
But when running the code it gives me this exception:
System.InvalidCastException: 'Unable to cast object of type 'System.Linq.Expressions.FullConditionalExpression' to type 'System.Linq.Expressions.UnaryExpression'.'
Any way I can do null checks on this Field property with using a UnaryExpression or an alternative way?
Thanks in advance