{"record":{"id":"c83e45767a8a5666","repo":"litedb-org/LiteDB","slug":"field-c83e45","errorCode":null,"errorMessage":"field","messagePattern":"field","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Mapper/EntityBuilder.cs","lineNumber":43,"sourceCode":"\n        /// <summary>\n        /// Define which property will not be mapped to document\n        /// </summary>\n        public EntityBuilder<T> Ignore<K>(Expression<Func<T, K>> member)\n        {\n            return this.GetMember(member, (p) =>\n            {\n                _entity.WaitForInitialization();\n                _entity.Members.Remove(p);\n            });\n        }\n\n        /// <summary>\n        /// Define a custom name for a property when mapping to document\n        /// </summary>\n        public EntityBuilder<T> Field<K>(Expression<Func<T, K>> member, string field)\n        {\n            if (field.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(field));\n\n            return this.GetMember(member, (p) =>\n            {\n                p.FieldName = field;\n            });\n        }\n\n        /// <summary>\n        /// Define which property is your document id (primary key). Define if this property supports auto-id\n        /// </summary>\n        public EntityBuilder<T> Id<K>(Expression<Func<T, K>> member, bool autoId = true)\n        {\n            return this.GetMember(member, (p) =>\n            {\n                _entity.WaitForInitialization();\n                \n                // if contains another _id, remove-it\n                var oldId = _entity.Members.FirstOrDefault(x => x.FieldName == \"_id\");","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Mapper/EntityBuilder.cs#L25-L61","documentation":"Thrown by EntityBuilder.Field(string) when the field name argument is null, empty, or whitespace. The field name becomes the stored document key; a blank name cannot be mapped. Reached from the fluent mapping configuration API (BsonMapper.Entity<T>().Field(...)).","triggerScenarios":"Calling builder.Field(x => x.Name, null), builder.Field(x => x.Name, \"\"), or builder.Field(x => x.Name, \"  \"). Also when the field name is read from a config/attribute that is unset.","commonSituations":"Renaming a field and leaving the new name empty during refactor, building field names from property names with a transformation that yields empty, or passing a constant that was never filled in.","solutions":["Pass a concrete non-empty field name string.","Validate the field name with string.IsNullOrWhiteSpace before configuring the mapping.","If the goal is to keep the default name, omit the Field() call entirely."],"exampleFix":"// before\nbuilder.Field(x => x.UserName, fieldName); // fieldName may be empty\n\n// after\nif (string.IsNullOrWhiteSpace(fieldName))\n    throw new InvalidOperationException(\"Field name is required.\");\nbuilder.Field(x => x.UserName, fieldName);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(field))\n    throw new ArgumentException(\"Field name is required.\", nameof(field));","typeGuard":"static bool IsValidFieldName(string s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":null,"preventionTips":["Omit Field() when you want the default name.","Use constants for field names to avoid empty strings during refactors."],"tags":["mapper","entity-builder","argument-null","field-name"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}