Skip to content

Commit

Permalink
Merge pull request #78 from Etherna/improve/MODM-177-mongo-driver-3
Browse files Browse the repository at this point in the history
migrate to mongo driver v3.0
  • Loading branch information
tmm360 authored Oct 25, 2024
2 parents 3fefb2c + 414322c commit 84374f0
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion samples/AspNetCoreSample/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// You should have received a copy of the GNU Lesser General Public License along with MongODM.
// If not, see <https://www.gnu.org/licenses/>.

using Etherna.MongoDB.Driver;
using Etherna.MongoDB.Driver.Linq;
using Etherna.MongODM.AspNetCoreSample.Models;
using Etherna.MongODM.AspNetCoreSample.Persistence;
using Microsoft.AspNetCore.Mvc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace Etherna.MongODM.Core.Conventions
{
public class HierarchicalProxyTolerantDiscriminatorConvention : IDiscriminatorConvention
public class HierarchicalProxyTolerantDiscriminatorConvention : IHierarchicalDiscriminatorConvention
{
// Fields.
private readonly IDbContext? _dbContext; //remove nullability with constructors that don't ask it, when will be possible
Expand Down
8 changes: 4 additions & 4 deletions src/MongODM.Core/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public static IEnumerable<TSource> Paginate<TSource, TKey>(
/// <param name="take">Elements per page</param>
/// <returns>Selected elements page</returns>
/// <exception cref="ArgumentOutOfRangeException">Throw with invalid parameter values</exception>
public static IMongoQueryable<TSource> Paginate<TSource, TKey>(
this IMongoQueryable<TSource> values,
public static IQueryable<TSource> Paginate<TSource, TKey>(
this IQueryable<TSource> values,
Expression<Func<TSource, TKey>> orderKeySelector,
int page,
int take)
Expand Down Expand Up @@ -114,8 +114,8 @@ public static IEnumerable<TSource> PaginateDescending<TSource, TKey>(
/// <param name="take">Elements per page</param>
/// <returns>Selected elements page</returns>
/// <exception cref="ArgumentOutOfRangeException">Throw with invalid parameter values</exception>
public static IMongoQueryable<TSource> PaginateDescending<TSource, TKey>(
this IMongoQueryable<TSource> values,
public static IQueryable<TSource> PaginateDescending<TSource, TKey>(
this IQueryable<TSource> values,
Expression<Func<TSource, TKey>> orderKeySelector,
int page,
int take)
Expand Down
9 changes: 4 additions & 5 deletions src/MongODM.Core/FieldDefinition/UnmappedFieldDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public UnmappedFieldDefinition(

// Methods.
public override RenderedFieldDefinition Render(RenderArgs<TDocument> args) =>
new(UnmappedFieldDefinitionHelper.BuildFieldPath(BaseDocumentField, UnmappedFieldName, args.DocumentSerializer, args.SerializerRegistry, args.LinqProvider),
new(UnmappedFieldDefinitionHelper.BuildFieldPath(BaseDocumentField, UnmappedFieldName, args.DocumentSerializer, args.SerializerRegistry),
UnmappedFieldSerializer);

public Type? TryGetBaseDocumentType(IBsonSerializer<TDocument> documentSerializer, IBsonSerializerRegistry serializerRegistry) =>
Expand Down Expand Up @@ -75,7 +75,7 @@ public UnmappedFieldDefinition(

// Methods.
public override RenderedFieldDefinition<TField> Render(RenderArgs<TDocument> args) =>
new(UnmappedFieldDefinitionHelper.BuildFieldPath(BaseDocumentField, UnmappedFieldName, args.DocumentSerializer, args.SerializerRegistry, args.LinqProvider),
new(UnmappedFieldDefinitionHelper.BuildFieldPath(BaseDocumentField, UnmappedFieldName, args.DocumentSerializer, args.SerializerRegistry),
UnmappedFieldSerializer,
UnmappedFieldSerializer,
UnmappedFieldSerializer);
Expand All @@ -90,13 +90,12 @@ public static string BuildFieldPath<TDocument>(
FieldDefinition<TDocument>? baseDocumentField,
string fieldName,
IBsonSerializer<TDocument> documentSerializer,
IBsonSerializerRegistry serializerRegistry,
LinqProvider linqProvider)
IBsonSerializerRegistry serializerRegistry)
{
var sb = new StringBuilder();
if (baseDocumentField is not null)
{
var baseDocRenderedField = baseDocumentField.Render(new(documentSerializer, serializerRegistry, linqProvider));
var baseDocRenderedField = baseDocumentField.Render(new(documentSerializer, serializerRegistry));
sb.Append(baseDocRenderedField.FieldName);
}
if (sb.Length > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.Core/MongODM.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<ItemGroup>
<PackageReference Include="Castle.Core" Version="5.1.1" />
<PackageReference Include="Etherna.MongoDB.Driver" Version="2.29.0" />
<PackageReference Include="Etherna.MongoDB.Driver" Version="3.0.1" />
<PackageReference Include="ExecutionContext" Version="1.3.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
6 changes: 3 additions & 3 deletions src/MongODM.Core/Repositories/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
// If not, see <https://www.gnu.org/licenses/>.

using Etherna.MongoDB.Driver;
using Etherna.MongoDB.Driver.Linq;
using Etherna.MongODM.Core.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -120,11 +120,11 @@ Task DeleteAsync(
CancellationToken cancellationToken = default);

Task<TResult> QueryElementsAsync<TResult>(
Func<IMongoQueryable<TModel>, Task<TResult>> query,
Func<IQueryable<TModel>, Task<TResult>> query,
AggregateOptions? aggregateOptions = null);

Task<PaginatedEnumerable<TResult>> QueryPaginatedElementsAsync<TResult, TResultKey>(
Func<IMongoQueryable<TModel>, IMongoQueryable<TResult>> filter,
Func<IQueryable<TModel>, IQueryable<TResult>> filter,
Expression<Func<TResult, TResultKey>> orderKeySelector,
int page,
int take,
Expand Down
4 changes: 2 additions & 2 deletions src/MongODM.Core/Repositories/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public string ModelIdToString(object model)
}

public virtual Task<TResult> QueryElementsAsync<TResult>(
Func<IMongoQueryable<TModel>, Task<TResult>> query,
Func<IQueryable<TModel>, Task<TResult>> query,
AggregateOptions? aggregateOptions = null) =>
AccessToCollectionAsync(collection =>
{
Expand All @@ -305,7 +305,7 @@ public virtual Task<TResult> QueryElementsAsync<TResult>(
});

public async Task<PaginatedEnumerable<TResult>> QueryPaginatedElementsAsync<TResult, TResultKey>(
Func<IMongoQueryable<TModel>, IMongoQueryable<TResult>> filter,
Func<IQueryable<TModel>, IQueryable<TResult>> filter,
Expression<Func<TResult, TResultKey>> orderKeySelector,
int page,
int take,
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.Core/Utility/DbMigrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
// You should have received a copy of the GNU Lesser General Public License along with MongODM.
// If not, see <https://www.gnu.org/licenses/>.

using Etherna.MongoDB.Driver;
using Etherna.MongoDB.Driver.Linq;
using Etherna.MongODM.Core.Domain.Models;
using Etherna.MongODM.Core.Extensions;
using Etherna.MongODM.Core.Tasks;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Etherna.MongODM.Core.Utility
Expand Down

0 comments on commit 84374f0

Please sign in to comment.