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

System.Linq.Dynamic.Core.DynamicQueryableExtensions.AsEnumerable conflicts with System.Linq.Enumerable.AsEnumerable #304

Closed
jbagley-iona opened this issue Sep 16, 2019 · 7 comments
Assignees
Labels

Comments

@jbagley-iona
Copy link

jbagley-iona commented Sep 16, 2019

I've run into an issue where the System.Linq.Dynamic.Core.DynamicQueryableExtensions.AsEnumerable extension method conflicts with the System.Linq.Enumerable.AsEnumerable extension method:

The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.AsEnumerable<TSource>(System.Collections.Generic.IEnumerable<TSource>)' and
 'System.Linq.Dynamic.Core.DynamicQueryableExtensions.AsEnumerable(System.Linq.IQueryable)'

I think this will become a more common issue with the upcoming release of EF Core 3.0 (where it will be necessary to explicitly force the enumeration of DB queries to avoid exceptions if they cannot be translated completely to SQL).

MoreLinq has similar issues and outlines a workaround in their documention (https://github.com/morelinq/MoreLINQ/blob/v3.1.0/README.md#usage). Would it be possible to do something similar in System.Linq.Dynamic.Core?

@StefH
Copy link
Collaborator

StefH commented Sep 16, 2019

If you want to apply the logic from this library on an IEnumerable, just to a AsQueryable() and continue to use this library.

@jbagley-iona
Copy link
Author

The problem I've run into is I have a class that makes use of both this library and System.Linq. In this class, I make use of System.Linq.AsEnumerable() to "switch" from an EF (IQueryable) query to a (IEnumerable) Linq-to-Objects query, but I cannot do that if the class also uses System.Linq.Dynamic.Core as it's .AsEnumerable() extension results in the error noted above.

@StefH
Copy link
Collaborator

StefH commented Sep 16, 2019

Just call the AsEnumerable() from System.Linq.Dynamic.Core with full name, like:

var result = System.Linq.Dynamic.Core.DynamicQueryableExtensions.AsEnumerable(x);

@jbagley-iona
Copy link
Author

Thanks. That's what I ended up doing but hoped there would be a better workaround (similar to what MoreLinq does). These are very large queries with multiple chained calls so having to break the query up to work around an ambiguous extension method issue is not ideal.

@slang25
Copy link

slang25 commented Sep 15, 2021

This is quite a big usability issue. With System.Linq being included as a default global namespace in C# 10 I can only seeing this getting more difficult.

It could be worth considering redesigning this API to co-exist with System.Linq.

@pgaske
Copy link

pgaske commented Nov 4, 2022

+1 - even though this is an old issue, still affecting me today when upgrading old codebases to ef6.

@StefH StefH self-assigned this Nov 5, 2022
@StefH
Copy link
Collaborator

StefH commented Nov 5, 2022

@pgaske & @slang25 & @jbagley-iona

I'll rename the extension method to AsDynamicEnumerable which should solve conflicts.

A new version will be released within a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants