optimise mongo repository

master
Young 6 months ago
parent 683a7b6f18
commit 948995d2ee

@ -1,6 +1,9 @@
namespace Infrastructure.Repository.Mongo;
using MongoDB.Bson.Serialization.Attributes;
public interface IIdentifiable
namespace Infrastructure.Repository.Mongo;
public interface IIdentifiable<TKey> where TKey : IEquatable<TKey>
{
string Id { get; set; }
[BsonId]
TKey Id { get; set; }
}

@ -3,7 +3,7 @@
namespace Infrastructure.Repository.Mongo;
public interface IMongoRepositoryBase<TEntity, in TKey>
where TEntity : class, IIdentifiable, new() where TKey : IEquatable<TKey>
where TEntity : class, IIdentifiable<TKey>, new() where TKey : IEquatable<TKey>
{
IMongoCollection<TEntity> Collection { get; }

@ -6,7 +6,7 @@ namespace Infrastructure.Repository.Mongo;
public abstract class MongoRepositoryBase<TEntity, TKey>(IMongoDatabase database) :
IMongoRepositoryBase<TEntity, TKey>
where TEntity : class, IIdentifiable, new()
where TEntity : class, IIdentifiable<TKey>, new()
where TKey : IEquatable<TKey>
{
private readonly IMongoCollection<TEntity> _collection = database.GetCollection<TEntity>(typeof(TEntity).Name);

Loading…
Cancel
Save