diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs index 32c0cc71bf..6f8d626bbe 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs @@ -1,9 +1,9 @@ -using JetBrains.Annotations; -using System; +using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Data; @@ -43,9 +43,9 @@ public abstract class BasicRepositoryBase : public IEntityChangeTrackingProvider EntityChangeTrackingProvider => LazyServiceProvider.LazyGetRequiredService(); public bool? IsChangeTrackingEnabled { get; protected set; } - + public string? EntityName { get; set; } - + public void SetEntityName(string? name) { EntityName = name; @@ -148,10 +148,10 @@ public abstract class BasicRepositoryBase : public abstract class BasicRepositoryBase : BasicRepositoryBase, IBasicRepository where TEntity : class, IEntity { - protected BasicRepositoryBase(string providerName) + protected BasicRepositoryBase(string providerName) : base(providerName) { - + } public virtual async Task GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default) @@ -160,7 +160,7 @@ public abstract class BasicRepositoryBase : BasicRepositoryBase(id); } return entity; diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs index 1277b9ceb8..62a13dd6b4 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs @@ -1,10 +1,10 @@ -using JetBrains.Annotations; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; @@ -60,7 +60,7 @@ public abstract class RepositoryBase : BasicRepositoryBase, IR if (entity == null) { - throw new EntityNotFoundException(typeof(TEntity)); + throw new EntityNotFoundException(); } return entity; @@ -101,7 +101,7 @@ public abstract class RepositoryBase : RepositoryBase, I : base(providerName) { } - + public abstract Task GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default); public abstract Task FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default); diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs index 70e69490a4..da0a25e4b6 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs @@ -56,7 +56,7 @@ public static class RepositoryExtensions { if (!await repository.AnyAsync(x => x.Id!.Equals(id), cancellationToken)) { - throw new EntityNotFoundException(typeof(TEntity), id); + throw new EntityNotFoundException(id); } } @@ -69,7 +69,7 @@ public static class RepositoryExtensions { if (!await repository.AnyAsync(expression, cancellationToken)) { - throw new EntityNotFoundException(typeof(TEntity)); + throw new EntityNotFoundException(); } } @@ -250,7 +250,7 @@ public static class RepositoryExtensions hardDeleteEntities.Add(entity); await repository.DeleteAsync(entity, autoSave, cancellationToken); } - + public static TRepository SetEntityName( this TRepository repository, string name diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 575dccadef..ff4aeabc44 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -1,6 +1,3 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Data; @@ -8,7 +5,10 @@ using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Volo.Abp.Domain.Entities; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.DependencyInjection; @@ -468,7 +468,7 @@ public class EfCoreRepository : EfCoreRepository(id); } return entity; @@ -480,7 +480,7 @@ public class EfCoreRepository : EfCoreRepository e.Id).FirstOrDefaultAsync(e => e.Id!.Equals(id), GetCancellationToken(cancellationToken)) : !ShouldTrackingEntityChange() ? await (await GetQueryableAsync()).OrderBy(e => e.Id).FirstOrDefaultAsync(e => e.Id!.Equals(id), GetCancellationToken(cancellationToken)) - : await (await GetDbSetAsync()).FindAsync(new object[] {id!}, GetCancellationToken(cancellationToken)); + : await (await GetDbSetAsync()).FindAsync(new object[] { id! }, GetCancellationToken(cancellationToken)); } public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default) diff --git a/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/Domain/Entities/EntityNotFoundException.cs b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/Domain/Entities/EntityNotFoundException.cs index 5f524f9578..ed10bf64c6 100644 --- a/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/Domain/Entities/EntityNotFoundException.cs +++ b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/Domain/Entities/EntityNotFoundException.cs @@ -2,6 +2,34 @@ namespace Volo.Abp.Domain.Entities; +/// +/// This exception is thrown if an entity is expected to be found but not found. +/// +public class EntityNotFoundException : EntityNotFoundException +{ + /// + /// Creates a new object. + /// + public EntityNotFoundException() + : base(typeof(TEntityType)) + { + } + /// + /// Creates a new object. + /// + public EntityNotFoundException(object? id) + : base(typeof(TEntityType), id) + { + } + /// + /// Creates a new object. + /// + public EntityNotFoundException(object? id, Exception? innerException) + : base(typeof(TEntityType), id, innerException) + { + } +} + /// /// This exception is thrown if an entity is expected to be found but not found. /// diff --git a/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index 9bef2a124a..c103c76b51 100644 --- a/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -334,7 +334,7 @@ public class MemoryDbRepository : MemoryDbRepos if (entity == null) { - throw new EntityNotFoundException(typeof(TEntity), id); + throw new EntityNotFoundException(id); } return entity; diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index a8cc1d39ae..4beb71d188 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -1,12 +1,12 @@ -using JetBrains.Annotations; -using MongoDB.Driver; -using MongoDB.Driver.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; +using MongoDB.Driver; +using MongoDB.Driver.Linq; using Volo.Abp.Auditing; using Volo.Abp.Data; using Volo.Abp.Domain.Entities; @@ -803,7 +803,7 @@ public class MongoDbRepository if (entity == null) { - throw new EntityNotFoundException(typeof(TEntity), id); + throw new EntityNotFoundException(id); } return entity;