Feat(Mapper): Support [Key] and [NotMapped] attributes from DataAnnotations
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.csto verify that[Key]and[NotMapped]attributes are correctly handled. -
Added a new benchmark (
InsertionIgnoreExpressionPropertyComponentModelBenchmark) to measure insertion performance when using property exclusion attributes.
Thanks for your contribution! Please see my comments.
@codex review
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".