Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Refactor IRepository and repository implementations

KrzysztofPajak99738a083e91
diff --git a/src/Core/Grand.Data/IRepository.cs b/src/Core/Grand.Data/IRepository.cs
index 05c7bec12..2590a73ee 100644
--- a/src/Core/Grand.Data/IRepository.cs
+++ b/src/Core/Grand.Data/IRepository.cs
@@ -206,5 +206,5 @@ public interface IRepository<T> where T : BaseEntity
/// <summary>
/// Gets a table collection
/// </summary>
- IQueryable<T> TableCollection(string collectionName);
+ IQueryable<C> TableCollection<C>() where C : class;
}
\ No newline at end of file
diff --git a/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs b/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs
index f179ab7e5..49109a0c8 100644
--- a/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs
+++ b/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs
@@ -1,6 +1,7 @@
using Grand.Domain;
using Grand.SharedKernel.Attributes;
using LiteDB;
+using System.Collections;
using System.Linq.Expressions;
using System.Reflection;
@@ -569,9 +570,9 @@ public class LiteDBRepository<T> : IRepository<T> where T : BaseEntity
/// <summary>
/// Gets a table collection
/// </summary>
- public virtual IQueryable<T> TableCollection(string collectionName)
+ public virtual IQueryable<C> TableCollection<C>() where C : class
{
- return _database.GetCollection<T>(collectionName).Query().ToEnumerable().AsQueryable();
+ return _database.GetCollection<C>(nameof(T)).Query().ToEnumerable().AsQueryable();
}
#endregion
diff --git a/src/Core/Grand.Data/Mongo/MongoRepository.cs b/src/Core/Grand.Data/Mongo/MongoRepository.cs
index fdb3a4847..1a4d6a97c 100644
--- a/src/Core/Grand.Data/Mongo/MongoRepository.cs
+++ b/src/Core/Grand.Data/Mongo/MongoRepository.cs
@@ -443,9 +443,9 @@ public class MongoRepository<T> : IRepository<T> where T : BaseEntity
/// <summary>
/// Gets a table collection
/// </summary>
- public virtual IQueryable<T> TableCollection(string collectionName)
+ public virtual IQueryable<C> TableCollection<C>() where C : class
{
- return _collection.Database.GetCollection<T>(collectionName).AsQueryable();
+ return _database.GetCollection<C>(typeof(T).Name).AsQueryable();
}
#endregion