-
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
OData URL creates invalid SQL Query 42P01: missing FROM-clause entry for table "t" #24877
Comments
We think this might already be fixed. Can you try using 6.0.0-preview4 or a daily build? |
Hi @AndriySvyryd , I updated the followings packages to <PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="6.0.0-preview.5.21264.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-preview.5.21268.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-preview.5.21268.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0-preview.5.21268.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-preview3" /> from <PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.5.1" /> After the package upgrade I had to change using statements in all EF designer files to using Microsoft.EntityFrameworkCore.Metadata; from using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; And get the following when trying to start the application: 2021-05-19T20:07:15.889Z [FTL] [Microsoft.AspNetCore.Hosting.WebHost][1] Application startup exception
System.ArgumentNullException: Value cannot be null. (Parameter 'type')
at System.Reflection.IntrospectionExtensions.GetTypeInfo(Type type)
at Microsoft.AspNet.OData.DefaultContainerBuilder.BuildContainer()
at Microsoft.AspNet.OData.PerRouteContainerBase.CreateODataRootContainer(Action`1 configureAction)
at Microsoft.AspNet.OData.PerRouteContainerBase.CreateODataRootContainer(String routeName, Action`1 configureAction)
at Microsoft.AspNet.OData.Extensions.ODataEndpointRouteBuilderExtensions.MapODataRoute(IEndpointRouteBuilder builder, String routeName, String routePrefix, Action`1 configureAction)
at Microsoft.AspNet.OData.Extensions.ODataEndpointRouteBuilderExtensions.MapODataRoute(IEndpointRouteBuilder builder, String routeName, String routePrefix, IEdmModel model, ODataBatchHandler batchHandler)
at Insite.Pim.OData.AppStart.ConfigureEndpointsAndMvc.<>c__DisplayClass2_0.<UseEndpoints>b__0(IEndpointRouteBuilder endpoints) in C:\_dev\repos\pim\Insite.Pim.OData\AppStart\ConfigureEndpointsAndMvc.cs:line 57
at Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder builder, Action`1 configure)
at Insite.Pim.OData.AppStart.ConfigureEndpointsAndMvc.UseEndpoints(IApplicationBuilder app, String pimHubPath, EnvironmentVariableProvider environmentVariableProvider) in C:\_dev\repos\pim\Insite.Pim.OData\AppStart\ConfigureEndpointsAndMvc.cs:line 50
at Insite.Pim.OData.Startup.Configure(IApplicationBuilder app, IHostApplicationLifetime applicationLifetime) in C:\_dev\repos\pim\Insite.Pim.OData\Startup.cs:line 105
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication() Any suggestions? |
@bmcdavidepi You are using "Npgsql.EntityFrameworkCore.PostgreSQL" with version "6.0.0-preview3". Preview versions are not compatible, wait for "6.0.0-preview4" to be released or use "6.0.0-preview3" for all packages. The exception you posted comes from OData and is also likely caused by version mismatch. @roji Is the |
@bmcdavidepi any chance you can post which type(s) required you to change the namespace to Npgsql.EntityFrameworkCore.PostgreSQL.Metadata? |
@roji, its the 'NpgsqlValueGenerationStrategy.SerialColumn' in the code below, which is in all of the migration designer files. modelBuilder
.HasAnnotation("Npgsql:PostgresExtension:citext", ",,")
.HasAnnotation("Npgsql:PostgresExtension:uuid-ossp", ",,")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.HasAnnotation("ProductVersion", "2.2.3-servicing-35854")
.HasAnnotation("Relational:MaxIdentifierLength", 63); |
Thanks @bmcdavidepi. Looks like I moved this type in 5488caf054f3b56c2b8ab33b34221d6aeffa8619 (npgsql/efcore.pg#339); this happened back in 2.1 - are you sure you're upgrading from 2.2? This probably wasn't the right thing to do, but it's been this way for a very long time now, with no particular problem (we generate the needed usings when scaffolding), and changing it now might cause the same problem in the other direction... Any thoughts @AndriySvyryd? Do you think I should move this (and others) back into Microsoft.EntityFrameworkCore? |
@roji When I go to definition on that type this is what I see #region Assembly Npgsql.EntityFrameworkCore.PostgreSQL, Version=5.0.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
// C:\Users\{MyUserName}\.nuget\packages\npgsql.entityframeworkcore.postgresql\5.0.5\lib\netstandard2.1\Npgsql.EntityFrameworkCore.PostgreSQL.dll
#endregion
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
{
public enum NpgsqlValueGenerationStrategy
{
None = 0,
SequenceHiLo = 1,
SerialColumn = 2,
IdentityAlwaysColumn = 3,
IdentityByDefaultColumn = 4
}
} |
@AndriySvyryd I changed the dependencies to this <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-preview.3.21201.13" /> Which does resolve the bad SQL query, could this change also be applied in a fix for the 5.x NuGet packages? |
@roji This is the relevant commit - npgsql/efcore.pg@926aa41 I think it should be reverted. At least until #18557 is implemented |
@bmcdavidepi We do not plan to bring the query fix to EF Core 5 due to the complexity/risk of the change. See release planning for more information on how we decide what to patch. |
@roji to take another look at the metadata change, since it seems to have been done very recently (Feb). |
@AndriySvyryd I see now, thanks for looking into this. So these were in Npgsql.EntityFrameworkCore.PostgreSQL since 2.1, and then moved to Microsoft.EntityFramework.Metadata for 6.0. to fix. Since this latest change was done to fix a scaffolding issue (npgsql/efcore.pg#1613) (and since these ultimately should be under Microsoft.EntityFramework.Metadata, I'm not sure it's much better to change back... it indeed means that users upgrading may have to manually add a using to their migrations, but I'm not sure it's that bad. We can discuss in triage/design. |
Note: see continued analysis into the Npgsql namespaces problem in #25046 |
I’m having issues with a code base we recently upgraded to .NET 5 from .NET Core 2.2. We use OData as a backend to a React frontend which uses OData calls to load data. Any help is greatly appreciated.
Below is a sample OData call that is creating an invalid Postgres SQL statement:
Invalid SQL
Stack trace
Include provider and version information
EF Core version: 5.0.5
Database provider: (Npgsql.EntityFrameworkCore.PostgreSQL Version="5.0.5.1")
OData: 7.5.8
Target framework: (NET 5.0)
Operating system: Windows 10
IDE: ( Visual Studio 2019 16.9.4)
The text was updated successfully, but these errors were encountered: