{"record":{"id":"562be5b19855ccd3","repo":"aspnetboilerplate/aspnetboilerplate","slug":"0-is-a-key-field-and-cannot-be-marked-readonly","errorCode":null,"errorMessage":"'{0}' is a key field and cannot be marked readonly.","messagePattern":"'(.+?)' is a key field and cannot be marked readonly\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Abp.Dapper/Dapper-Extensions/Mapper/MemberMap.cs","lineNumber":197,"sourceCode":"        public MemberMap Ignore()\n        {\n            if (KeyType != KeyType.NotAKey && KeyType != KeyType.SlapperIdentifierKey)\n            {\n                throw new ArgumentException(string.Format(\"'{0}' is a key field and cannot be ignored.\", Name));\n            }\n\n            Ignored = true;\n            return this;\n        }\n\n        /// <summary>\n        /// Fluently sets the read-only status of the property.\n        /// </summary>\n        public MemberMap ReadOnly()\n        {\n            if (KeyType != KeyType.NotAKey && KeyType != KeyType.SlapperIdentifierKey)\n            {\n                throw new ArgumentException(string.Format(\"'{0}' is a key field and cannot be marked readonly.\", Name));\n            }\n\n            IsReadOnly = true;\n            return this;\n        }\n\n        /// <summary>\n        /// Fluently sets the field length of the property\n        /// </summary>\n        /// <param name=\"size\">The length of the field as it exists in the database</param>\n        public MemberMap Size(int size)\n        {\n            if (size < 0)\n            {\n                throw new ArgumentException(string.Format(\"'{0}' cannot have a negative field length.\", Name));\n            }\n\n            DbSize = size;","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/aspnetboilerplate/aspnetboilerplate/blob/2323c13a152aa0ebfb37af3830f687d7f5b53795/src/Abp.Dapper/Dapper-Extensions/Mapper/MemberMap.cs#L179-L215","documentation":"Guard in MemberMap.ReadOnly(): the member {0} has a KeyType other than NotAKey and SlapperIdentifierKey, i.e. it is an active key field. Marking a key read-only would prevent the mapper from writing key values during insert/update, so the fluent ReadOnly() call is rejected with this ArgumentException.","triggerScenarios":"Thrown at src/Abp.Dapper/Dapper-Extensions/Mapper/MemberMap.cs:197 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not call ReadOnly() on a key member; apply ReadOnly() only to non-key properties.","Move the key mapping to a writable property and keep {0} read-only if it must not be persisted.","Skip the ReadOnly() call for key members and control write behavior at the database/key-generation level instead."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}