FluentFTP icon indicating copy to clipboard operation
FluentFTP copied to clipboard

Ambiguous call when using LINQ extension method and ef core

Open bastienchauvin opened this issue 5 years ago • 9 comments

Hello, I have a problem on ambiguous reference between EF Core and System.Linq because projects reference System.Linq.Async. When I clone the repo, and delete this reference, add local reference to the dll, there is no problem. Could you generate a release without this ? Or have you a solution ?

bastienchauvin avatar Apr 06 '21 21:04 bastienchauvin

A workaround to disambiguate the two extensions methods ToListAsync is to cast your DbSet<T> to an IQueryable<T>, since only the EF Core version of ToListAsync works on these.

using FluentFTP;
using Microsoft.EntityFrameworkCore;
using System.Linq;

namespace ConsoleApp37
{
    class MySet : DbSet<object>
    {
    }

    class Program
    {
        static void Main(string[] args)
        {
            new FtpClient().GetListingAsyncEnumerable().ToListAsync();
            ((IQueryable<object>)new MySet()).ToListAsync();
        }
    }
}

From a class design perspective you would maybe want to separate the responsibilities of interacting with an FTP and a database into two separate classes.

jnyrup avatar Apr 08 '21 06:04 jnyrup

@jnyrup Thanks for helping!

robinrodricks avatar Apr 08 '21 06:04 robinrodricks

@bastienchauvin You want me to delete the ref to System.Linq.Async for which platform(s)? And are you having issues with ToListAsync as Jonas mentioned?

robinrodricks avatar Apr 08 '21 06:04 robinrodricks

After update from 33.0 to 3.1 I get many errors in my project when calling where clauses on db context like this:

The call does not clearly distinguish between the following methods or properties: "System.Linq.Queryable.Where (System.Linq.IQueryable , System.Linq.Expressions.Expression <System.Func <TSource, bool >>)" and "System.Linq.AsyncEnumerable.Where (System.Collections.Generic.IAsyncEnumerable , System.Func <TSource, bool>)"

here is an example call with ambiguities in the where clause

            var filialArtikelDaten = await _ctx.FilialArtikeldaten
                                               .Where(fa => fa.ArtikelId == Guid.Empty)
                                               .ToListAsync(cancellationToken)
                                               .ConfigureAwait(false);

JanLorenz77 avatar Apr 09 '21 13:04 JanLorenz77

Then it's a new issue and I'll look into it.

On Fri, Apr 9, 2021, 6:49 PM JanLorenz77 @.***> wrote:

After update from 33.0 to 3.1 I get many errors in my project when calling where clauses on db context like this:

The call does not clearly distinguish between the following methods or properties: "System.Linq.Queryable.Where (System.Linq.IQueryable , System.Linq.Expressions.Expression <System.Func <TSource, bool >>)" and "System.Linq.AsyncEnumerable.Where (System.Collections.Generic.IAsyncEnumerable , System.Func <TSource, bool>)"

here is an example call with ambiguities in the where clause var filialArtikelDaten = await _ctx.FilialArtikeldaten .Where(fa => fa.ArtikelId == Guid.Empty) .ToListAsync(cancellationToken) .ConfigureAwait(false);

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/robinrodricks/FluentFTP/issues/703#issuecomment-816676070, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABT3UKSDSDPEF22F2N3DSWDTH35FFANCNFSM42PRTNNA .

robinrodricks avatar Apr 09 '21 15:04 robinrodricks

Then it's a new issue and I'll look into it.

Existing Linq queries will no longer work after the update to 33.1.x. This has to do with the addition of System.Linq.Async. Can this additional package be removed?

ghost avatar Apr 23 '21 13:04 ghost

@nbakx-vbe @JanLorenz77 @jnyrup Done. Please check:

https://www.nuget.org/packages/FluentFTP/33.1.7

robinrodricks avatar Apr 24 '21 15:04 robinrodricks

Yes this solves all the LINQ errors

ghost avatar Apr 26 '21 06:04 ghost

Great!

robinrodricks avatar Apr 27 '21 12:04 robinrodricks