efcore icon indicating copy to clipboard operation
efcore copied to clipboard

IncludeProperties is ambiguous between the Microsoft.EntityFrameworkCore.SqlServerIndexBuilderExtensions.IncludeProperties and the Microsoft.EntityFrameworkCore.NpgsqlIndexBuilderExtensions.IncludeProperties

Open tdolgyras opened this issue 6 years ago • 7 comments

We have issue with the use of IncludeProperties, because in our project we have SqlServer and PostgreSql.

The error is also mentioned in efcore.pg team. https://github.com/npgsql/efcore.pg/issues/1334

The call is ambiguous between the following methods or properties: 
'Microsoft.EntityFrameworkCore.SqlServerIndexBuilderExtensions.IncludeProperties<TEntity>
(Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder<TEntity>, System.Linq.Expressions.Expression<System.Func<TEntity, object>>)' 
and 
'Microsoft.EntityFrameworkCore.NpgsqlIndexBuilderExtensions.IncludeProperties<TEntity>
(Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder<TEntity>, System.Linq.Expressions.Expression<System.Func<TEntity, object>>)'	

We think that there should be more specific guidelines for ef core providers authors, about the namespaces they should use so this issues like this one wan't occurred.

tdolgyras avatar Apr 29 '20 15:04 tdolgyras

@tdolgyras This is currently by-design. It's unusual for an application to pull in multiple providers, so we optimize the experience for the single provider application. In cases like this you can call the extension methods as normal methods instead.

ajcvickers avatar Apr 29 '20 16:04 ajcvickers

@tdolgyras note the code sample in https://github.com/npgsql/efcore.pg/issues/1334 which shows how to call the extension methods as normal methods.

roji avatar Apr 29 '20 18:04 roji

With EF Core 5.x, the migration snapshots now appear to use .IncludeProperties(), which makes this more of a pain to workaround (generated code => can't use extension methods explicitly).

However, a solution I've found which works is to add a file within the Migrations folder as follows:

namespace MyProject.Migrations {
    public static class ExtensionMethodFixes {
        public static IndexBuilder IncludeProperties(this IndexBuilder builder, params string[] propertyNames) {
            return NpgsqlIndexBuilderExtensions.IncludeProperties(builder, propertyNames);
        }
    }
}

and then the snapshots within the folder will then use that extension method unambiguously.

bbycroft avatar Aug 24 '21 04:08 bbycroft

@bbycroft 5.0 migrations model snapshots should contain annotations for IncludeProperties, rather than method calls, precisely to avoid this issue (see https://github.com/dotnet/efcore/issues/23456#issuecomment-755557722).

6.0 generates type-qualifed calls for provider annotations, so you'd get NpgsqlIndexBuilderExtensions.IncludeProperties in the model snapshot (see https://github.com/dotnet/efcore/pull/25435). This should be testable in the upcoming 6.0.0-rc1 release.

roji avatar Aug 24 '21 14:08 roji

Have the same issue when I even don't have any PostgreSql packages (.NET 6) and use only 1 SQL server provider.

Den4ikzxcv avatar Apr 15 '24 11:04 Den4ikzxcv

@Den4ikzxcv Please open a new issue and attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

ajcvickers avatar Apr 15 '24 11:04 ajcvickers

@ajcvickers oh, thanks for reply, I want to update project to the newest .NET version and if this issue will still persist I will back to you soon, thanks :)

Den4ikzxcv avatar Apr 15 '24 11:04 Den4ikzxcv