'Ambiguous Match Found in .NET 6.0 with DbContext
When executing this code, I get "Ambiguous Match Found" when targeting .NET 6.0, using Entity Framework Core 6.0.3.
context.GetType().GetMethod("Set")
It happens on all of my model types, and I've tried EF Core 6.0.2 and 6.0.0.
Using .NET Core 3.1, there is no problem with the same code.
Anybody else getting this?
Solution 1:[1]
Use the overload of GetMethod (string name, int genericParameterCount, Type[] types) when you only have a Type instance of the desired DbSet.
Example:
Type t = [type of DbSet you need]
var results = context.GetType()
.GetMethod("Set", 1, Type.EmptyTypes)
.MakeGenericMethod(t)
.Invoke(context, null);
This invokes the Set method of DbContext that takes no parameters, but expects a genericParameter.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Marco |
