Uh oh!
There was an error while loading. Please reload this page.
Allow for specify return value on System.Linq.Enumerable.*OrDefault methods - #48886
Conversation
ghost
commented
Feb 28, 2021
Tagging subscribers to this area: @eiriktsarpalis |
Are the errors here code issues or an issue with changes being synced? I haven't contributed since the dotnet runtime was split across several repositories so I'm not familiar with all that's going on behind the scenes. Edit: Didn't push ref assemblies. This has been resolved. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
eiriktsarpalis
left a comment
There was a problem hiding this comment.
Please add unit tests for the new methods as well. Thanks.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
eiriktsarpalis
commented
Mar 8, 2021
Hi @Foxtrek64, have you been able to take a look at PR feedback? Thanks! |
TheBrambleShark
commented
Mar 9, 2021
Yes. Sorry, I've had a busy few days. I'll implement these changes tomorrow and have them ready for review. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
eiriktsarpalis
left a comment
There was a problem hiding this comment.
Please add similar unit tests for the overloads accepting predicates.
approved accidentally, PR still has pending feedback
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
eiriktsarpalis
left a comment
There was a problem hiding this comment.
Other than some minor changes, LGTM.
Thank you for your contribution!
eiriktsarpalis
commented
Mar 14, 2021
Thanks @Foxtrek64. Note that there are a few failing unit tests related to these changes. Could you take a look? |
I did notice what I think was a logic error on my part and patched it. Hopefully it resolves the test issues, or at least some of them. I tried testing on my ends but I get strange results, like Edit: I've fixed this issue but now I'm running into issues with the Queryable side of things. After hashing this out in the .Net Foundation Discord, we believe this to be an issue with the BCL itself in that the overload I'm attempting to implement does not exist there. I'm not entirely sure doing something like this is even possible given that it would require splitting things into multiple queries on the BCL side. I can "fix" it by doing something like this: [DynamicDependency("FirstOrDefault`1",typeof(Enumerable))]publicstaticTSourceFirstOrDefault<TSource>(thisIQueryable<TSource>source,Expression<Func<TSource,bool>>predicate,TSourcedefaultValue){if(source==null)throwError.ArgumentNull(nameof(source));if(predicate==null)throwError.ArgumentNull(nameof(predicate));usingvarresult=source.Where(predicate).Take(1).GetEnumerator();if(result.MoveNext())returnresult.Current;returndefaultValue;// Skip this stuff/* return source.Provider.Execute<TSource>( Expression.Call( null, CachedReflectionInfo.FirstOrDefault_TSource_4(typeof(TSource)), source.Expression, Expression.Quote(predicate), Expression.Constant(defaultValue, typeof(TSource)) )); */}But this is less than ideal for the obvious reason that it cannot be used in the inner part of a query, like this: varquery=context.SomeTable.Select(t =>t.SubTable.Select(st =>st.Value).FirstOrDefault(v =>v>0,-1));@eiriktsarpalis@stephentoub How would you recommend going about this? It may be best to only update Alternatively, if you two or anyone else has any ideas, I'm all ears. It may be possible to implement this in an appropriate manner, but I'm not entirely certain what that might look like. |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
eiriktsarpalis
commented
Mar 17, 2021
@Foxtrek64 I rebased your branch and added fixes for the failing tests. |
TheBrambleShark
commented
Mar 17, 2021
Seems a mix of me just being blind and missing a couple things and some random number being wrong somewhere that I would have never thought to look at. Glad we got that sorted. |
eiriktsarpalis
commented
Mar 18, 2021
Thanks @Foxtrek64! |
Fixes#20064