0

today I have faced a situation that broke all my working code. And I need some adveice please.

I am accessing the database using EF Core 5 and here is an example of how to access.

await Context.EntityName.Where(p => p.Id==id).FirstOrDefaultAsync(cancellationToken);

this code was working totaly fine but some how I started to get below error.

Error   CS0121  The call is ambiguous between the following methods or properties: 'System.Linq.Queryable.Where<TSource>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource, bool>>)' and 'System.Linq.AsyncEnumerable.Where<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)'

I don't know why this error happened but only way to work aroung the problem is the adding .AsQueryable() before the Where

await Context.EntityName.AsQueryable().Where(p => p.Id==id).FirstOrDefaultAsync(cancellationToken);

Any idea what all this about ? why suddenly it happened ?

I have almost 1000 line code to change :(

S. Aziz Kazdal
  • 1,126
  • 3
  • 16
  • 40
  • 2
    Check here for an answer https://stackoverflow.com/questions/60347952/ambiguous-call-when-using-linq-extension-method-on-dbsett – JoeyD Oct 06 '21 at 16:01
  • well I saw that but the thing I can not understand is that all code was working until today ? I have working with net 5 since it's came out as this way. but today code has been broken. @JoeyD – S. Aziz Kazdal Oct 06 '21 at 16:14
  • 2
    @S.AzizKazdal Well, looks like you've added reference to System.Linq.Async package in your project which is causing the name clash/ambiguity. The issue with System.Linq.Async will be resolved in the upcoming EF Core 6.0 - see https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-6.0/whatsnew#smoother-integration-with-systemlinqasync. Until then, there is no good solution. – Ivan Stoev Oct 06 '21 at 17:09
  • 1
    @IvanStoev thank you. One of the package that use System.Linq.Async was causing the problem. RepoDB (v 1.12.9) downgraded the package for now. – S. Aziz Kazdal Oct 06 '21 at 19:25

0 Answers0