Skip to content

DOCSP-49279: $convert stage LINQ method #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 17, 2025

Conversation

rustagir
Copy link
Collaborator

@rustagir rustagir commented Apr 16, 2025

Pull Request Info

PR Reviewing Guidelines

JIRA - https://jira.mongodb.org/browse/DOCSP-49279

Staging Links

  1. linq section
  2. whats new

Self-Review Checklist

  • Is this free of any warnings or errors in the RST?
  • Did you run a spell-check?
  • Did you run a grammar-check?
  • Are all the links working?
  • Are the facets and meta keywords accurate?
  • Are the page titles greater than 20 characters long and SEO relevant?

Copy link

netlify bot commented Apr 16, 2025

Deploy Preview for docs-csharp ready!

Name Link
🔨 Latest commit c5251dc
🔍 Latest deploy log https://app.netlify.com/sites/docs-csharp/deploys/680119976a55eb000803ef70
😎 Deploy Preview https://deploy-preview-604--docs-csharp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@jordan-smith721 jordan-smith721 left a comment

Choose a reason for hiding this comment

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

LGTM w/ a couple quick fixes

@rustagir rustagir requested a review from papafe April 16, 2025 14:39
Comment on lines 632 to 635
.. code-block:: csharp

var query = queryableCollection
.Select(r => Mql.Convert(r.RestaurantId, new ConvertOptions<int>()));
Copy link
Collaborator Author

@rustagir rustagir Apr 16, 2025

Choose a reason for hiding this comment

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

Hi @papafe would you prefer if we showed a more complex example that uses the options?

Copy link

Choose a reason for hiding this comment

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

I think the example is fine, it's difficult to make a more complex example using the dataset we have in this page. But at least you can show OnError or OnNull. So it could be:

   var query = queryableCollection
       .Select(r => Mql.Convert(r.RestaurantId, new ConvertOptions<int>( OnError = -1, OnNull = 0 )));

$convert
~~~~~~~~

You can use the ``Mql.Convert()`` method in a ``Select()`` projection to
Copy link

Choose a reason for hiding this comment

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

The use of Mql.Convert is not limited only to Select, even though it could be the most common.

Comment on lines 632 to 635
.. code-block:: csharp

var query = queryableCollection
.Select(r => Mql.Convert(r.RestaurantId, new ConvertOptions<int>()));
Copy link

Choose a reason for hiding this comment

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

I think the example is fine, it's difficult to make a more complex example using the dataset we have in this page. But at least you can show OnError or OnNull. So it could be:

   var query = queryableCollection
       .Select(r => Mql.Convert(r.RestaurantId, new ConvertOptions<int>( OnError = -1, OnNull = 0 )));

$convert
~~~~~~~~

You can use the ``Mql.Convert()`` method in a ``Select()`` projection to
Copy link

Choose a reason for hiding this comment

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

I can see from the other operators in the page that usually we first introduce briefly the operator, and then show how to use it in LINQ. Maybe we should follow that pattern?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved some sections around to distinguish between stages/operators

The ``Convert()`` method takes the following parameters:

- Value to convert.
- ``ConvertOptions<Tto>`` instance that specifies the type to convert to
Copy link

Choose a reason for hiding this comment

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

Here we can omit TTo, as we did not introduce it before.

@rustagir rustagir requested a review from papafe April 16, 2025 19:05
Copy link

@papafe papafe left a comment

Choose a reason for hiding this comment

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

It looks good, just a small correction and it's done.

.. code-block:: csharp

var query = queryableCollection
.Select(r => Mql.Convert(r.RestaurantId, new ConvertOptions<int>( OnError = -1, OnNull = 0 )));
Copy link

Choose a reason for hiding this comment

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

Suggested change
.Select(r => Mql.Convert(r.RestaurantId, new ConvertOptions<int>( OnError = -1, OnNull = 0 )));
.Select(r => Mql.Convert(r.RestaurantId, new ConvertOptions<int> { OnError = -1, OnNull = 0 }));

My bad, I used the wrong parenthesis in the example 🤦

@rustagir rustagir requested a review from papafe April 17, 2025 15:09
Copy link

@papafe papafe left a comment

Choose a reason for hiding this comment

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

LGTM

@rustagir rustagir merged commit 46f9b7b into mongodb:master Apr 17, 2025
5 of 6 checks passed
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.

3 participants