{"record":{"id":"e9dc841420cc5a4b","repo":"dotnet/efcore","slug":"the-operation-operation-cannot-be-performed-on-e9dc84","errorCode":null,"errorMessage":"The operation '{operation}' cannot be performed on keyless entity type '{entityType}', since it contains an operator not natively supported by the database provider.","messagePattern":"The operation '(.+?)' cannot be performed on keyless entity type '(.+?)', since it contains an operator not natively supported by the database provider\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs","lineNumber":98,"sourceCode":"            if (!IsMemberAccess(\n                    RemapLambdaBody(source, firstPropertySelector).UnwrapTypeConversion(out _),\n                    RelationalDependencies.Model,\n                    out var baseExpression)\n                || _sqlTranslator.TranslateProjection(baseExpression) is not StructuralTypeShaperExpression shaper)\n            {\n                throw new InvalidOperationException(RelationalStrings.InvalidPropertyInSetProperty(firstPropertySelector));\n            }\n\n            // TODO: #36336\n            if (shaper.StructuralType is not IEntityType entityType)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.ExecuteUpdateSubqueryNotSupportedOverComplexTypes(shaper.StructuralType.DisplayName()));\n            }\n\n            if (entityType.FindPrimaryKey() is not { } pk)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.ExecuteOperationOnKeylessEntityTypeWithUnsupportedOperator(\n                        nameof(EntityFrameworkQueryableExtensions.ExecuteUpdate),\n                        entityType.DisplayName()));\n            }\n\n            // Generate the INNER JOIN around the original query, on the PK properties.\n            var outer = (ShapedQueryExpression)Visit(new EntityQueryRootExpression(entityType));\n            var inner = source;\n            var outerParameter = Expression.Parameter(entityType.ClrType);\n            var outerKeySelector = Expression.Lambda(outerParameter.CreateKeyValuesExpression(pk.Properties), outerParameter);\n            var firstPropertyLambdaExpression = setters[0].PropertySelector;\n            var entitySource = GetEntitySource(RelationalDependencies.Model, firstPropertyLambdaExpression.Body);\n            var innerKeySelector = Expression.Lambda(\n                entitySource.CreateKeyValuesExpression(pk.Properties), firstPropertyLambdaExpression.Parameters);\n\n            var joinPredicate = CreateJoinPredicate(outer, outerKeySelector, inner, innerKeySelector);\n\n            Check.DebugAssert(joinPredicate != null, \"Join predicate shouldn't be null\");","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs#L80-L116","documentation":"Thrown when ExecuteUpdate (or ExecuteDelete) targets a keyless entity type. Bulk update/delete generates an INNER JOIN on the entity's primary key columns; a keyless entity has no PK, so the join cannot be constructed and the operation is rejected with the 'operator not natively supported' framing.","triggerScenarios":"Defining an entity type with HasNoKey() and then calling ExecuteUpdate/ExecuteDelete on a query rooted at it, or on a query (e.g. a view or TVF) that resolves to a keyless entity. The source region shows the check `entityType.FindPrimaryKey() is not { } pk` failing for ExecuteUpdate; the same helper fires for ExecuteDelete in the sibling file.","commonSituations":"Mapping database views, raw SQL results, or query results as keyless entities and attempting bulk modifications; forgetting that a HasNoKey entity cannot participate in write operations.","solutions":["Add a primary key to the entity type via HasKey(...) / Key(...) so ExecuteUpdate can join back to the table.","If the type is genuinely keyless and read-only, do not call ExecuteUpdate/ExecuteDelete on it; load, mutate, and SaveChanges on a keyed entity instead.","Switch the bulk operation to run against a keyed entity type that maps to the same table."],"exampleFix":"// before\nmodelBuilder.Entity<EagleQuery>().HasNoKey();\nawait ctx.Set<EagleQuery>().ExecuteUpdateAsync(s => s.SetProperty(e => e.Name, \"x\"));\n// after\nmodelBuilder.Entity<Eagle>().HasKey(e => e.Id);\nawait ctx.Set<Eagle>().ExecuteUpdateAsync(s => s.SetProperty(e => e.Name, \"x\"));","handlingStrategy":"validation","validationCode":"// Verify the entity has a primary key before calling ExecuteUpdate/ExecuteDelete.\nIEntityType? et = ctx.Model.FindEntityType(typeof(EagleQuery));\nif (et?.FindPrimaryKey() is null)\n{\n    throw new InvalidOperationException($\"{et?.DisplayName()} is keyless; bulk update not supported.\");\n}\nawait ctx.Set<EagleQuery>().ExecuteUpdateAsync(s => s.SetProperty(e => e.Name, \"x\"));","typeGuard":null,"tryCatchPattern":"try { await query.ExecuteUpdateAsync(setters); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"keyless entity type\"))\n{\n    logger.LogWarning(\"Bulk update on keyless entity is not supported: {Msg}\", ex.Message);\n    // fall back to load + SaveChanges on a keyed entity\n}","preventionTips":["Reserve HasNoKey for genuinely read-only view/TVF mappings.","Add a build-time test that asserts every entity used with ExecuteUpdate has a key.","Document keyless types in the project as read-only."],"tags":["efcore","executeupdate","executedelete","keyless-entity","query-translation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}