Skip to content
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

Update QueryBuilder.cs #84

Merged
merged 1 commit into from
Jun 17, 2022
Merged

Update QueryBuilder.cs #84

merged 1 commit into from
Jun 17, 2022

Conversation

markikordahi
Copy link
Contributor

Check null before accessing nested object

Check null before accessing nested object
@tghamm
Copy link
Owner

tghamm commented Jun 16, 2022

Hi @markikordahi thanks! I don't suppose you could write a quick unit test just to help me better understand the case this protects against for posterity could you?

@markikordahi
Copy link
Contributor Author

markikordahi commented Jun 16, 2022

i had the same issue "#61"
as an example, i have a student class and a Course class. student can have 0 1 or many classes.
when searching for allstudents with class name = "ABC" this was building below query which was throwing object not set to an instance of an object since Any was trying to access courses which is null (when student have 0 course)
item.Courses.AsQueryable().Any(Param_0 => ((True == True) AndAlso (Param_0.bookId.ToString().ToLower() == \"1\".ToLower())))
so now the query will look like this
((item.Courses != null) AndAlso item.Courses.AsQueryable().Any(Param_0 => ((True == True) AndAlso (Param_0.bookId.ToString().ToLower() == \"1\".ToLower()))))

@tghamm
Copy link
Owner

tghamm commented Jun 16, 2022

Thanks for clarifying, I'll take a look.

@tghamm tghamm merged commit 9aab019 into tghamm:master Jun 17, 2022
tghamm added a commit that referenced this pull request Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants