Skip to content

Added BsonRefId<T> to allow explicit DbRefs in LINQ expressions#2741

Merged
JKamsker merged 8 commits intolitedb-org:devfrom
rklfss:allow_updatemany_expressions_with_dbref
Feb 27, 2026
Merged

Added BsonRefId<T> to allow explicit DbRefs in LINQ expressions#2741
JKamsker merged 8 commits intolitedb-org:devfrom
rklfss:allow_updatemany_expressions_with_dbref

Conversation

@rklfss
Copy link
Copy Markdown

@rklfss rklfss commented Feb 6, 2026

With this PR, a LINQ expression helper type BsonRefId<T> is introduced that allows explicit setting of DbRef objects in LINQ expressions, for example in UpdateMany.

db.GetCollection<A>()
    .UpdateMany(
        x => new A
        {
            Id = x.Id,
            Bref = new BsonRefId<B>(100), // instead of `new B { }` which would be included inline
        },
        x => x.Id == 11);

Resolves #2739

JKamsker and others added 5 commits September 29, 2025 21:54
This document outlines the Code of Conduct for community members, detailing pledges, standards of behavior, enforcement responsibilities, and consequences for violations.
Updated build status badge and added pre-release badge.
…ressions_with_dbref

# Conflicts:
#	LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs
@JKamsker
Copy link
Copy Markdown
Collaborator

JKamsker commented Feb 6, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a046a5be5c

ℹ️ 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".

Comment thread LiteDB.Tests/Mapper/LinqBsonExpression_Tests.cs Outdated
@JKamsker
Copy link
Copy Markdown
Collaborator

JKamsker commented Feb 6, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2df20d84d2

ℹ️ 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".

Comment thread LiteDB/Client/Mapper/MemberMapper.cs Outdated
Comment on lines +52 to +55
/// <summary>
/// Is this property an DbRef? Must implement Serialize/Deserialize delegates
/// </summary>
public bool IsDbRef { get; set; }
public bool IsDbRef => DbRefCollectionName != null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore public DbRef configuration for custom mappers

The commit makes MemberMapper.IsDbRef read-only and ties it to the new internal DbRefCollectionName, which means external code can no longer mark a member as a DbRef in ResolveMember or other custom mapping hooks. This is a breaking change for consumers who previously set member.IsDbRef = true (and optionally supplied custom serialize/deserialize) without using [BsonRef] or EntityBuilder.DbRef. Because DbRefCollectionName is internal, there is now no public way to achieve the same configuration, so existing mapping code will fail to compile or silently lose DbRef behavior. Consider keeping a public setter or exposing a public way to set the collection name.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JKamsker How to handle this? I understand the point, but don't see how to just set the IsDbRef flag (in ResolveMember?) would lead to something useful. Doing this manual currently requires also to set a pretty complex Serialize/Deserialize method. I would even go further and try to make the Entity/Member mappers themselves internal, letting the generic ResolveMember method use some builder approach like it exists for the EntityBuilder.

@JKamsker JKamsker merged commit 0086a5c into litedb-org:dev Feb 27, 2026
4 checks passed
@JKamsker
Copy link
Copy Markdown
Collaborator

Thanks for the pr!

@rklfss rklfss deleted the allow_updatemany_expressions_with_dbref branch February 27, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants