{"record":{"id":"4e963822bffb4af0","repo":"aspnetboilerplate/aspnetboilerplate","slug":"sequenceidentity-generator-cannot-be-used-with-mul","errorCode":null,"errorMessage":"SequenceIdentity generator cannot be used with multi-column keys","messagePattern":"SequenceIdentity generator cannot be used with multi-column keys","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Abp.Dapper/Dapper-Extensions/DapperImplementor.cs","lineNumber":559,"sourceCode":"\n            var dynamicParameters = new DynamicParameters();\n\n            foreach (var prop in entity.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.GetField | BindingFlags.Instance | BindingFlags.Public)\n                .Where(p => !keyColumns.Any(k => k.Name.Equals(p.Name)) && !foreignKeys.Contains(p) && !ignoredColumns.Contains(p)\n                ))\n                dynamicParameters = AddParameter(entity, dynamicParameters, new MemberMap(prop), useColumnAlias);\n\n            return dynamicParameters;\n        }\n\n        public DynamicParameters GetDynamicParameters<T>(IClassMapper classMap, T entity, bool useColumnAlias = false)\n        {\n            var sequenceIdentityColumn = classMap.Properties.Where(p => p.KeyType == KeyType.SequenceIdentity)?.ToList();\n            var foreignKeys = classMap.Properties.Where(p => p.KeyType == KeyType.ForeignKey).Select(p => p.MemberInfo).ToList();\n            var ignored = classMap.Properties.Where(x => x.Ignored).Select(p => p.MemberInfo).ToList();\n\n            if (sequenceIdentityColumn?.Count > 1)\n                throw new ArgumentException(\"SequenceIdentity generator cannot be used with multi-column keys\");\n\n            return GetDynamicParameters(entity, classMap, sequenceIdentityColumn, foreignKeys, ignored, useColumnAlias);\n        }\n\n        public DynamicParameters GetDynamicParameters<T>(T entity, DynamicParameters dynamicParameters, IMemberMap keyColumn, bool useColumnAlias = false)\n        {\n            dynamicParameters ??= new DynamicParameters();\n            foreach (var prop in entity.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public)\n                .Where(p => p.Name != keyColumn.Name))\n                AddParameter(entity, dynamicParameters, new MemberMap(prop), useColumnAlias);\n\n            return dynamicParameters;\n        }\n\n        /// <summary>\n        /// Return property liste from (anonymous) type\n        /// </summary>\n        /// <typeparam name=\"T\"></typeparam>","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/aspnetboilerplate/aspnetboilerplate/blob/2323c13a152aa0ebfb37af3830f687d7f5b53795/src/Abp.Dapper/Dapper-Extensions/DapperImplementor.cs#L541-L577","documentation":"This ArgumentException is thrown by DapperImplementor when an entity mapped with the DapperExtensions fluent mapper has more than one property marked as KeyType.SequenceIdentity. SequenceIdentity keys rely on a database sequence to generate a single identity value, so the library only supports exactly one such key per entity and refuses to build insert parameters otherwise.","triggerScenarios":"Calling GetDynamicParameters (or any insert path that reaches it, e.g. DapperExtensions.Insert) on a ClassMapper whose Properties contain two or more properties with KeyType == KeyType.SequenceIdentity (Key SequenceIdentity(...)).","commonSituations":"Copy-pasting fluent mapping lines so a composite-key entity ends up with two SequenceIdentity entries; refactoring a Guid key to a sequence key on one property while leaving the old mapping; bulk-generating mappings from templates.","solutions":["Inspect the entity's ClassMapper mapping and keep only ONE property mapped with KeyType.SequenceIdentity","Change the additional key properties to KeyType.Assigned or mark them Ignored if they are not real keys","If a true composite key is needed, use KeyType.Assigned for all key columns instead of SequenceIdentity"],"exampleFix":"// before\nMap(x => x.Id).Key(KeyType.SequenceIdentity);\nMap(x => x.RowId).Key(KeyType.SequenceIdentity);\n// after\nMap(x => x.Id).Key(KeyType.SequenceIdentity);\nMap(x => x.RowId).Key(KeyType.Assigned);","handlingStrategy":"validation","validationCode":"var seqKeys = mapper.Properties.Count(p => p.KeyType == KeyType.SequenceIdentity);\nif (seqKeys > 1) throw new InvalidOperationException(\"Entity must have at most one SequenceIdentity key\");","typeGuard":null,"tryCatchPattern":"try { DapperExtensions.Insert(connection, entity); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"SequenceIdentity\"))\n{\n    // fix mapping or fall back to Assigned keys\n}","preventionTips":["Keep exactly one SequenceIdentity key per entity mapping","Review ClassMapper classes for copy-pasted Key() lines","Write a unit test asserting each mapper has at most one sequence key"],"tags":["orm","mapping","dapper","configuration"],"backgroundTag":"invalid-config-value","analyzedSha":"2323c13a152aa0ebfb37af3830f687d7f5b53795","analyzedAt":"2026-09-08T08:00:50.638Z","contentChangedAt":"2026-09-08T08:00:50.638Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}