LiteDB icon indicating copy to clipboard operation
LiteDB copied to clipboard

Feat(Mapper): Support [Key] and [NotMapped] attributes from DataAnnotations

Open lucafabbri opened this issue 1 month ago • 3 comments

This PR enhances the BsonMapper to recognize common attributes from System.ComponentModel.DataAnnotations, improving interoperability with other frameworks like Entity Framework.

Changes:

  • [Key] as [BsonId]: The [Key] attribute is now recognized as an alias for [BsonId(AutoId = false)].

  • [NotMapped] as [BsonIgnore]: The [NotMapped] attribute is now recognized as an alias for [BsonIgnore].

To avoid adding new dependencies to older target frameworks (like .NET Standard 2.0), this functionality is conditionally compiled and only active for projects targeting .NET 8 or newer (#if NET8_0_OR_GREATER).

Verification:

  • Added new unit tests in CustomMapping_Tests.cs to verify that [Key] and [NotMapped] attributes are correctly handled.

  • Added a new benchmark (InsertionIgnoreExpressionPropertyComponentModelBenchmark) to measure insertion performance when using property exclusion attributes.

lucafabbri avatar Nov 02 '25 15:11 lucafabbri

Thanks for your contribution! Please see my comments.

JKamsker avatar Nov 02 '25 15:11 JKamsker

@codex review

JKamsker avatar Nov 05 '25 22:11 JKamsker

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".