Mixing named and positional parameters isn't supported
See original GitHub issueHi,
we are experiencing this issue after upgrading from .NET Core 3.1 to .NET 6 (including the EF Core and Npgsql update, of course). These exceptions are being thrown from multiple queries. I am aware that the exception is thrown from Npgsql driver, but something is probably be wrong here or in EF Core. Unfortunatelly, I am not able to create some unit test or a toy project where I could reproduce it. It happens only in our large project. My guess is that there is either a race somewhere or some parameter objects are being reused and not reinitialized properly. Even in the large project, the same query can be executed fine multiple times and then it fails randomly.
Here is an example from debugger:
CommandText = SELECT a.id, a.generations_to_save, a.enabled, a.schedule_json FROM public.auto_backup AS a LIMIT 2
On our side, the query is as simple as this (no params):
using var context = _dbScope.CreateNoTrackingDbContext();
var entity = await context.AutoBackup.SingleAsync(cancellationToken);
Another example from the debugger:
CommandText = SELECT v.current_usn, v.id FROM ( SELECT public.get_database_id() as id, last_value as current_usn FROM public.server_usn_seq ) AS v LIMIT 2
On our side, it is a raw query with no parameters:
const string metadataSql = "SELECT public.get_database_id() as id, last_value as current_usn FROM public.server_usn_seq";
return await context.CreateQuery<DatabaseMetadata>()
.FromSqlRaw(rawSql)
.SingleAsync(cancellationToken);
But this happens also to parametrized queries, for example: CommandText =
FROM public.account AS a
WHERE (EXISTS (
SELECT 1
FROM public.account_subscription AS a0
WHERE (a0.subscription_id = @__gSubscriptionId_0) AND (a0.account_id = a.id)) AND ((a.state = 'created'::account_state_enum) AND (a.expiration_date IS NULL OR (a.expiration_date > now())))) AND a.is_deleted_time_utc IS NULL
ORDER BY a.purpose = 'service'::account_purpose_enum DESC
LIMIT 1
On our side it looks like this:
var accountIds = context.AccountSubscription
.Where(connSub => connSub.SubscriptionId == gSubscriptionId)
.Select(connSub => connSub.AccountId);
query = context.Account
.OrderByDescending(acc => acc.Purpose == AccountPurpose.Service)
.Where(acc => accountIds.Contains(acc.Id))
.Where(acc => acc.State == AzureAccountStateEnum.Created && (acc.ExpirationDate == null || acc.ExpirationDate > DateTime.UtcNow));
query = query.ExcludeDeleted();
var result = await query.FirstOrDefaultAsync(ct);
Could you please help with this issue? It is a show stopper for us when it comes to the upgrade to .NET 6.
Thanks, Martin
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:7 (7 by maintainers)
I confirm it works
And thanks again for the investigation and the fix!