Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "sergii"

I've decided to use SaveChanges approaches, works good, thank you.

Hi, I have this try/catch block in my app services

try
            {
                newEntity = _repository.Insert(newEntity);
                CurrentUnitOfWork.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                var validationErrors = ex.EntityValidationErrors?.SelectMany(e => e.ValidationErrors?.Select(v => new ValidationResult(v.ErrorMessage, new string[] { v.PropertyName }))).ToList();
                throw new AbpValidationException(FriendlyMessages.FormDataValidationFailed, validationErrors);
            }

I want to move above handler for DbEntityValidationException from App Services to some single base level and seems it can be done via implementing and registering IExceptionToErrorInfoConverter via IErrorInfoBuilder.AddExceptionConverter(IExceptionToErrorInfoConverter converter)

The question is where from I can get acces to IErrorInfoBuilder for app service ? Or maybe someone could advise another good approach to have above handler in one place and to be used by all app services by default

Hi, thank you for answer. Yes, the issue was in migration scripts... Resolved by recreating database and new migration scripts.

Correct, but I've fixed my issue by removing method overloads: Was

IEnumerable<EntityDto> GetAllAssignments(int p1);
IEnumerable<EntityDto> GetAllAssignments(int p1, int p2);

Now

IEnumerable<EntityDto> GetAllAssignments(int p1, int p2=0);

Same issue with api method

http://localhost:6234/api/services/app/program/GetAllAssignments?id=1
{"message":"An error has occurred.","exceptionMessage":"There is an action GetAllAssignments defined for api controller app/program but with a different HTTP Verb. Request verb is GET. It should be Post","exceptionType":"Abp.AbpException","stackTrace":"   at Abp.WebApi.Controllers.Dynamic.Selectors.AbpApiControllerActionSelector.GetActionDescriptorByActionName(HttpControllerContext controllerContext, DynamicApiControllerInfo controllerInfo, String actionName) in D:\\Halil\\GitHub\\aspnetboilerplate\\src\\Abp.Web.Api\\WebApi\\Controllers\\Dynamic\\Selectors\\AbpApiControllerActionSelector.cs:line 95\r\n   at Abp.WebApi.Controllers.Dynamic.Selectors.AbpApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext) in D:\\Halil\\GitHub\\aspnetboilerplate\\src\\Abp.Web.Api\\WebApi\\Controllers\\Dynamic\\Selectors\\AbpApiControllerActionSelector.cs:line 48\r\n   at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n   at Castle.Proxies.DynamicApiController`1Proxy_3.ExecuteAsync_callback(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n   at Castle.Proxies.Invocations.ApiController_ExecuteAsync_3.InvokeMethodOnTarget()\r\n   at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n   at Abp.WebApi.Controllers.Dynamic.Interceptors.AbpDynamicApiControllerInterceptor`1.Intercept(IInvocation invocation) in D:\\Halil\\GitHub\\aspnetboilerplate\\src\\Abp.Web.Api\\WebApi\\Controllers\\Dynamic\\Interceptors\\AbpDynamicApiControllerInterceptor.cs:line 57\r\n   at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n   at Castle.Proxies.DynamicApiController`1Proxy_3.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.&lt;SendAsync&gt;d__1.MoveNext()"}

Could someone say what is best practice to work with enums like AddressType, Country so on but stored on DB side ? Should I load them every time via repository before I want to assign them ?

// app service code
var newOffice1  = new Office () {Name="Some Name", TypeId=officeDto.TypeId   }
officeRepository.Insert(newOffice1 );
// or ?
var newOffice2  = new Office () {Name="Some Name", Type=officeRepository.Get(officeDto.TypeId)  }
officeRepository.Insert(newOffice2 );

//
// domain code
public class Office :  Entity<int>
{
        public virtual string Name { get; set; }

        public virtual int TypeId { get; set; }
        [ForeignKey("TypeId")]
        public virtual OfficeType OfficeType { get; set; }
}

// read only,  can't be added or updated, with coded conversion by ID to c# enum
public class OfficeType :  Entity<int>
{
        public virtual string Name { get; set; }
        public virtual string Description{ get; set; }
}

At very first run I have the exception, only HangFire tables have been created and DB locked after the exception raised

Server Error in '/' Application.

There is no such an entity with given primary key. Entity type: MyTest.MultiTenancy.Tenant, primary key: 1

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Abp.AbpException: There is no such an entity with given primary key. Entity type: MyTest.MultiTenancy.Tenant, primary key: 1

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[AbpException: There is no such an entity with given primary key. Entity type: MyTest.MultiTenancy.Tenant, primary key: 1]
   Abp.Domain.Repositories.AbpRepositoryBase`2.Get(TPrimaryKey id) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Repositories\AbpRepositoryBase.cs:70
   Castle.Proxies.EfRepositoryBase`2Proxy_2.Get_callback(Int32 id) +5
   Castle.Proxies.Invocations.AbpRepositoryBase`2_Get_8.InvokeMethodOnTarget() +67
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:53
   Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:45
   Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:35
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.EfRepositoryBase`2Proxy_2.Get(Int32 id) +155
   Abp.MultiTenancy.TenantCache`2.GetTenant(Int32 tenantId) in D:\Halil\GitHub\module-zero\src\Abp.Zero\MultiTenancy\TenantCache.cs:60
   Castle.Proxies.TenantCache`2Proxy.GetTenant_callback(Int32 tenantId) +5
   Castle.Proxies.Invocations.TenantCache`2_GetTenant.InvokeMethodOnTarget() +67
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:53
   Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:45
   Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:35
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.TenantCache`2Proxy.GetTenant(Int32 tenantId) +155
   Abp.MultiTenancy.<>c__DisplayClass4_0.<Get>b__0() in D:\Halil\GitHub\module-zero\src\Abp.Zero\MultiTenancy\TenantCache.cs:37
   Abp.Runtime.Caching.<>c__DisplayClass0_0`2.&lt;Get&gt;b__0(TKey k) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\TypedCacheExtensions.cs:13
   Abp.Runtime.Caching.&lt;&gt;c__DisplayClass3_0`2.<Get>b__0(String k) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\CacheExtensions.cs:28
   Abp.Runtime.Caching.CacheBase.Get(String key, Func`2 factory) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\CacheBase.cs:42
   Abp.Runtime.Caching.CacheExtensions.Get(ICache cache, TKey key, Func`2 factory) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\CacheExtensions.cs:28
   Abp.Runtime.Caching.TypedCacheWrapper`2.Get(TKey key, Func`2 factory) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\TypedCacheWrapper.cs:52
   Abp.Runtime.Caching.TypedCacheExtensions.Get(ITypedCache`2 cache, TKey key, Func`1 factory) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\TypedCacheExtensions.cs:13
   Abp.MultiTenancy.TenantCache`2.Get(Int32 tenantId) in D:\Halil\GitHub\module-zero\src\Abp.Zero\MultiTenancy\TenantCache.cs:31
   Castle.Proxies.TenantCache`2Proxy.Get_callback(Int32 tenantId) +5
   Castle.Proxies.Invocations.TenantCache`2_Get.InvokeMethodOnTarget() +66
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:29
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.TenantCache`2Proxy.Get(Int32 tenantId) +155
   Abp.Zero.EntityFramework.DbPerTenantConnectionStringResolver.GetNameOrConnectionString(DbPerTenantConnectionStringResolveArgs args) in D:\Halil\GitHub\module-zero\src\Abp.Zero.EntityFramework\Zero\EntityFramework\DbPerTenantConnectionStringResolver.cs:51
   Abp.Zero.EntityFramework.DbPerTenantConnectionStringResolver.GetNameOrConnectionString(ConnectionStringResolveArgs args) in D:\Halil\GitHub\module-zero\src\Abp.Zero.EntityFramework\Zero\EntityFramework\DbPerTenantConnectionStringResolver.cs:46
   Abp.Domain.Uow.UnitOfWorkBase.ResolveConnectionString(ConnectionStringResolveArgs args) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkBase.cs:332
   Abp.EntityFramework.Uow.EfUnitOfWork.GetOrCreateDbContext(Nullable`1 multiTenancySide) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\EfUnitOfWork.cs:145
   Abp.EntityFramework.Uow.UnitOfWorkExtensions.GetDbContext(IActiveUnitOfWork unitOfWork, Nullable`1 multiTenancySide) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\UnitOfWorkExtensions.cs:38
   Abp.EntityFramework.Uow.UnitOfWorkDbContextProvider`1.GetDbContext(Nullable`1 multiTenancySide) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\UnitOfWorkDbContextProvider.cs:38
   Castle.Proxies.EfRepositoryBase`3Proxy_11.get_Context_callback() +46
   Castle.Proxies.Invocations.EfRepositoryBase`3_get_Context_14.InvokeMethodOnTarget() +28
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:53
   Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:45
   Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:35
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.EfRepositoryBase`3Proxy_11.get_Context() +126
   Abp.EntityFramework.Repositories.EfRepositoryBase`3.get_Table() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Repositories\EfRepositoryBaseOfTEntityAndTPrimaryKey.cs:30
   Castle.Proxies.EfRepositoryBase`3Proxy_11.get_Table_callback() +5
   Castle.Proxies.Invocations.EfRepositoryBase`3_get_Table_14.InvokeMethodOnTarget() +28
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:53
   Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:45
   Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:35
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.EfRepositoryBase`3Proxy_11.get_Table() +126
   Abp.EntityFramework.Repositories.EfRepositoryBase`3.InsertAsync(TEntity entity) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Repositories\EfRepositoryBaseOfTEntityAndTPrimaryKey.cs:80
   Castle.Proxies.EfRepositoryBase`3Proxy_11.InsertAsync_callback(AuditLog entity) +5
   Castle.Proxies.Invocations.EfRepositoryBase`3_InsertAsync_14.InvokeMethodOnTarget() +68
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Abp.Domain.Uow.UnitOfWorkInterceptor.PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:62
   Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:41
   Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:35
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.EfRepositoryBase`3Proxy_11.InsertAsync(AuditLog entity) +141
   Abp.Auditing.AuditingStore.SaveAsync(AuditInfo auditInfo) in D:\Halil\GitHub\module-zero\src\Abp.Zero\Auditing\AuditingStore.cs:24
   Abp.Auditing.&lt;&gt;c__DisplayClass0_0.&lt;Save&gt;b__0() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Auditing\AuditingStoreExtensions.cs:17
   System.Threading.Tasks.Task`1.InnerInvoke() +56
   System.Threading.Tasks.Task.Execute() +49
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Nito.AsyncEx.<>c__DisplayClass3.<Run>b__1(Task t) +56
   System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke() +52
   System.Threading.Tasks.Task.Execute() +49
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Nito.AsyncEx.AsyncContext.Run(Func`1 action) +201
   Abp.Auditing.AuditingStoreExtensions.Save(IAuditingStore auditingStore, AuditInfo auditInfo) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Auditing\AuditingStoreExtensions.cs:17
   Abp.Web.Mvc.Controllers.AbpController.HandleAuditingAfterAction(ActionExecutedContext filterContext) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.Web.Mvc\Web\Mvc\Controllers\AbpController.cs:466
   Castle.Proxies.AccountControllerProxy.OnActionExecuted_callback(ActionExecutedContext filterContext) +5
   Castle.Proxies.Invocations.AbpController_OnActionExecuted.InvokeMethodOnTarget() +69
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:29
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.AccountControllerProxy.OnActionExecuted(ActionExecutedContext filterContext) +142
   System.Web.Mvc.Controller.System.Web.Mvc.IActionFilter.OnActionExecuted(ActionExecutedContext filterContext) +9
   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass46.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__3f() +253
   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass33.&lt;BeginInvokeActionMethodWithFilters&gt;b__32(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c() +26
   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass21.&lt;BeginInvokeAction&gt;b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
   Castle.Proxies.AccountControllerProxy.EndExecuteCore_callback(IAsyncResult asyncResult) +4
   Castle.Proxies.Invocations.Controller_EndExecuteCore.InvokeMethodOnTarget() +55
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:29
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.AccountControllerProxy.EndExecuteCore(IAsyncResult asyncResult) +142
   System.Web.Mvc.Controller.&lt;BeginExecute&gt;b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   Castle.Proxies.AccountControllerProxy.EndExecute_callback(IAsyncResult asyncResult) +26
   Castle.Proxies.Invocations.Controller_EndExecute.InvokeMethodOnTarget() +55
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:29
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.AccountControllerProxy.EndExecute(IAsyncResult asyncResult) +142
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.&lt;BeginProcessRequest&gt;b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9644097
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0
Showing 11 to 17 of 17 entries