Skip to content

feat: Upgrade major mongo version #418

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 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="9.0.4" />
<PackageVersion Include="MongoDB.Driver" Version="2.30.0" />
<PackageVersion Include="MongoDB.Driver" Version="3.3.0" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.3.efcore.9.0.0" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
<PackageVersion Include="RavenDB.Client" Version="7.0.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async ValueTask<IPagedList<T>> GetAllAsync(Expression<Func<T, bool>>? fil
await repository.GetAllAsync(filter, orderBy, descending, page, pageSize);

public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
Expression<Func<T, TProjection>>? selector,
Expression<Func<T, TProjection>> selector,
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

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

The updated non-nullable selector parameter mandates that a projection must always be provided; verify that cached calls conform to this requirement.

Copilot uses AI. Check for mistakes.

Expression<Func<T, bool>>? filter = null,
Expression<Func<T, object>>? orderBy = null,
bool descending = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ValueTask<IPagedList<TEntity>> GetAllAsync(
int pageSize = int.MaxValue);

ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
Expression<Func<TEntity, TProjection>>? selector,
Expression<Func<TEntity, TProjection>> selector,
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

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

By removing the nullable annotation, the repository interface now requires a non-null selector; ensure that implementations and consumers are consistent with this change.

Suggested change
Expression<Func<TEntity, TProjection>> selector,
Expression<Func<TEntity, TProjection>> selector, // Must not be null

Copilot uses AI. Check for mistakes.

Expression<Func<TEntity, bool>>? filter = null,
Expression<Func<TEntity, object>>? orderBy = null,
bool descending = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ public static class MongoDBConnectionProvider
{
public static IMongoDatabase Create(string connectionString, string databaseName)
{
#pragma warning disable IDISP001 // Handled by DI container
#pragma warning disable CA2000 // Handled by DI container
var client = new MongoClient(connectionString);
#pragma warning restore CA2000
#pragma warning restore IDISP001
BsonClassMap.RegisterClassMap<Entity>(cm =>
{
cm.AutoMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Driver.Linq;

namespace LinkDotNet.Blog.Infrastructure.Persistence.MongoDB;

public static class PaginatedListQueryExtensions
{
public static async Task<IPagedList<T>> ToPagedListAsync<T>(this IMongoQueryable<T> source, int pageIndex, int pageSize, CancellationToken token = default)
public static async Task<IPagedList<T>> ToPagedListAsync<T>(this IQueryable<T> source, int pageIndex, int pageSize, CancellationToken token = default)
{
var count = await source.CountAsync(token);
if (count > 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using LinkDotNet.Blog.Domain;
Expand Down Expand Up @@ -51,7 +52,7 @@ public async ValueTask<IPagedList<TEntity>> GetAllAsync(Expression<Func<TEntity,
await GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize);

public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
Expression<Func<TEntity, TProjection>>? selector,
Expression<Func<TEntity, TProjection>> selector,
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

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

The change to a non-nullable selector enforces that a valid projection is always provided; confirm that downstream callers are updated accordingly.

Copilot uses AI. Check for mistakes.

Expression<Func<TEntity, bool>>? filter = null,
Expression<Func<TEntity, object>>? orderBy = null,
bool descending = true,
Expand All @@ -70,8 +71,9 @@ public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProject
query = descending ? query.OrderByDescending(orderBy) : query.OrderBy(orderBy);
}

var projectionQuery = query.Select(selector);
return await projectionQuery.ToPagedListAsync(page, pageSize);
return await query
.Select(selector)
.ToPagedListAsync(page, pageSize);
}

public async ValueTask StoreAsync(TEntity entity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ValueTask<IPagedList<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>
GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize);
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

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

The selector parameter is now required; update any RavenDB repository calls to supply a non-null expression.

Suggested change
GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize);
GetAllByProjectionAsync(selector: s => s, filter, orderBy, descending, page, pageSize);

Copilot uses AI. Check for mistakes.


public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
Expression<Func<TEntity, TProjection>>? selector,
Expression<Func<TEntity, TProjection>> selector,
Expression<Func<TEntity, bool>>? filter = null,
Expression<Func<TEntity, object>>? orderBy = null,
bool descending = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ValueTask<IPagedList<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>
GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize);

Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

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

The selector parameter is now non-nullable; ensure that all consumers of this repository pass a valid non-null selector expression.

Suggested change
/// <summary>
/// Retrieves a paginated list of entities projected to a specific type.
/// The selector parameter must not be null.
/// </summary>

Copilot uses AI. Check for mistakes.

public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
Expression<Func<TEntity, TProjection>>? selector,
Expression<Func<TEntity, TProjection>> selector,
Expression<Func<TEntity, bool>>? filter = null,
Expression<Func<TEntity, object>>? orderBy = null,
bool descending = true,
Expand Down