-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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.Interactive.Async call is ambiguous error when IX-Async is referenced #18124
Comments
@shravan2x - Ways to deal with this
|
All of those solutions are basically non-starters. I worked around this by defining some extension methods: internal static class DbSetExtensions
{
public static IAsyncEnumerable<T> AsAsyncEnumerable<T>(this DbSet<T> dbSet)
where T : class
{
return dbSet;
}
public static IQueryable<T> AsQueryable<T>(this DbSet<T> dbSet)
where T : class
{
return dbSet;
}
}
|
@smitpatel Your answer is not helpful at all.
Additionally, you didn't mention that using namespace aliases allows you to only specify the full type specification of one of the libraries, in case it is used much more often than the other. But i'm already aware of all these solutions. I posted this issue to engage constructive conversation on how to improve our API surface and find a permanent solution, especially since async LINQ methods are very useful. Since your solution doesn't address my problem, please reopen the issue. |
@shravan2x - Ambiguity in method resolution arises in compiler. There can be more ways to work-around the issue. I am not sure how can we improve API surface for some issue which is compiler issue rather than EF. We do not want to change Name FirstOrDefaultAsync or change interfaces implemented by DbSet. If you have any other idea, do tell us. |
@smitpatel I notice that this issue only occurs when the If you prefer, I can prepare a repro. @carlreinke Your solution works great! |
EF Core 2.2 used IX-Async package for async enumerables. In 3.0 EF Core does not depend on IX-Async rather uses IAsyncEnumerable from compiler directly. |
I've updated my code to use @carlreinke 's solution. I'm fairly happy with it. Overall, you're right that this problem is hard to solve without changing the interfaces implemented by However, (if I understand correctly), this problem occurs because |
Exactly. It is not common to use both libraries in same project, where both method namespaces needs to be imported in same file where you are using raw DbSet to apply an async operation. Hence there is very little value to add a base class and not confuse other users which are using DbSet in normal way. Work-arounds posted above etc are good way to handle the corner case where customers run into it. |
I don't know why you think that. I'm using async-LINQ to finish up the parts of queries that can't be translated to SQL. People use |
I found out that this is worse than that, forget I hope I am wrong and I messed up somewhere, because I can't believe such a simple use case can be broken. |
Ok so for those stuck, I ended up adding several extensions method at the root namespace of my project. This work because the compiler prefer extension methods in the current or parent namespace before looking the usings. public static IAsyncEnumerable<TEntity> AsAsyncEnumerable<TEntity>(this Microsoft.EntityFrameworkCore.DbSet<TEntity> obj) where TEntity : class
{
return Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AsAsyncEnumerable(obj);
}
public static IQueryable<TEntity> Where<TEntity>(this Microsoft.EntityFrameworkCore.DbSet<TEntity> obj, System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate) where TEntity : class
{
return System.Linq.Queryable.Where(obj, predicate);
} Please tell me this is not the only workaround, and I fucked up somewhere, how could something like that could have been missed? |
I tested it even further, AsAsyncEnumerable, which we suggest as using work-around does not work either since it also has ambiguity. The root cause is, IX-async has put methods in |
After discussing again and re-investigating there doesn't seem to be anything we can do here. It would be a "normal" conflicting methods in two different namespaces problem, except that since, as @smitpatel says, IX-async decided to put their methods into |
@smitpatel actually I remember I saw a way to remove ambiguity of namespace conflicts in C#.... trying to find again/ |
So for those stuck on https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias When I will fix it in my own code later, I will publish a clean solution here. @ajcvickers @smitpatel I understand why you close this issue, but this is a big design mistake you did here. Those namespace conflicts will create countless of issues to noobs trying to figure out what is happening. Even me, coding in C# for more than 10 years non stop, I got confused... Because you probably don't want to make breaking change again, you will probably not change this decision, but still, ef did a huge design mistake. You are making EF impossible to use with other libraries without using an obscure feature of the C# language that yourself don't even know, and causing endless of conflict of You should better remove interfaces from dbset, just coding classic method |
@NicolasDorier -
Such methods if defined in BCL which everyone would be using by default make sense but not in external libraries. |
@NicolasDorier If there's something we can do in EF Core to make this better, then please suggest. We will consider it, even if it is a breaking change, based on how much help it would be and based on how much it would impact other experiences. |
@ajcvickers this should never happen #18220 it happens whenever you reference namepace System.Linq and EF in the same file. You can solve it by not implementing |
|
Same, why is this issue closed? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
* Merge query and saving async pages * Move under fundamentals * Document ambiguous invocation issues with System.Interactive.Async and show workaround. Closes #1722 Related to #1332 Related to dotnet/efcore#18124
* Merge query and saving async pages * Move under fundamentals * Document ambiguous invocation issues with System.Interactive.Async and show workaround. Closes #1722 Related to #1332 Related to dotnet/efcore#18124
* Merge query and saving async pages * Move under fundamentals * Document ambiguous invocation issues with System.Interactive.Async and show workaround. Closes #1722 Related to #1332 Related to dotnet/efcore#18124
* Merge query and saving async pages * Move under fundamentals * Document ambiguous invocation issues with System.Interactive.Async and show workaround. Closes #1722 Related to #1332 Related to dotnet/efcore#18124
* Refactor and improve async documentation * Merge query and saving async pages * Move under fundamentals * Document ambiguous invocation issues with System.Interactive.Async and show workaround. Closes #1722 Related to #1332 Related to dotnet/efcore#18124
That's really funny coming from the same team that recommends converting |
It would be good to re-open this, at least for tracking purposes. The Reactive team considers this to be a design issue in EF Core: |
I like how |
The way |
FYI, for EF Core 6.0, DbSet will no longer be implementing IAsyncEnumerable, removing the ambiguity and the need to call AsQueryable - see #24041 for more details and background. |
…syncEnumerator` (this introduces an ambiguaty, see dotnet/efcore#18124, which will be removed in EF Core 6.0, see dotnet/efcore#18124 (comment), but until then it requires us to call `AsQueryable` on `DbSet` before calling `Where`)
Try the following and see it works. It worked successfully for me. Instead of:
you just need:
|
I'm using .NET Core 3.0 with EF Core and System.Interactive.Async. Using methods like FirstOrDefaultAsync and Where results in compilation errors like
Steps to reproduce
Further technical details
EF Core version: 3.0.0
Database provider: Sqlite
Target framework: .NET Core 3.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.3
The text was updated successfully, but these errors were encountered: