-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null propagation cannot be used for primitive type lists (string) #366
Comments
Can you try MyGet version |
Looks good:
|
@Franki1986 Can you do some more tests please? To make sure it works also on real database calls? |
Sure, I will do it tomorow. But I am using Linqtodb not ef core. But if the expression is right I think it will also work with ef.. |
I am not sure what kind of test scenario I could do against a database? If I understand, I have to generate a methodExpression that could return null. |
Instead of using DynamicExpressionParser manually, you can just use a Linq Select: Example: var resultDynamic = DBContext.MyClasses.AsQueryable().Select("np(MyList.FirstOrDefault())"); |
I hope this is getting in the right direction, because it is the closest I can create with the database and LinqToDb, because a string list cannot be mapped directly to a database table and the expression then coould only be applied to the resulting data. So I created a parent and child class for 1 to n.
Resulting expression debug string:
The result list is the same.. |
And if you get the Id and provide a default value, like: var query2 = query .Select("np(r.ChildList.FirstOrDefault().Id, 42)"); |
Sorry for the late response, I wasn't at the pc over the easter days.
produces the expression:
which returns 42 for Ids that would return null. Works! |
@Franki1986 Thanks a lot for this test. |
LinqToDb didn't have eager loading till version 3 (pre release), so this is the SQL that is produced for a version under 3, where for each child a subselect is done:
and so on... |
Is this sufficent for you? |
Yes. I will merge PR and release new version. |
I want to parse a null propagation expression for a list with a string:
Simple test scenario:
Here I get the exception : The 'np' (null-propagation) function requires the first argument to be a MemberExpression
Null propagation for a property works:
The text was updated successfully, but these errors were encountered: