Base solution for your next web application

Activities of "adamphones"

What we would like is to be able to send friendly message back to client for all Microsoft.EntityFrameworkCore.DbUpdateException instead of sending back 500 invalid exception message : "An error occurred while updating the entries. See the inner exception for details."

version: asp zero 8.1 angular

`public class Schedule{

public DateTime EffectiveFrom {get;set;}

public DateTime EffectiveTo {get;set;} } ` We would like to enforce user to enter EndDate greater than StartDate. We tried ICustomValidate interface as below.

public void AddValidationErrors(CustomValidationContext context) { if (EffectiveTo.HasValue && EffectiveTo.Value.Date < EffectiveFrom.Date) { context.Results.Add(new ValidationResult("Effective To must be greater than Effective From date.")); } }

The validation seems work but on the client side we get an exception as 'Method arguments are not valid! See ValidationErrors for details.' But the client cannot really see which field has the issue or whether the EffectiveTo date should be greater than Effective From date.

One way to fix this issue would be to implement validation on angular in the client side. However we were wonder whether there is a better way to represent these validation issues to the client?

Regarding to this we could only see this document https://aspnetboilerplate.com/Pages/Documents/Validating-Data-Transfer-Objects#introduction-to-validation

Do you have any other documentation which explains data validation?

My second question which relates to this is that whether it is possible to generically create validations? What I mean by this is that instead of having validation on each class to implement "AddValidationErrors" seperate that outside of the class. The reason being is that we have a lot of entities that has the properties EffectiveFrom and EffectiveTo and they all need validation as EffectiveTo> EffectiveFrom. It would be nice to have single validation for those properties and automatically plug it into each class through interface maybe? Any idea on this?

I would appriciate your help on this topic.

Regards,

Thanks for coming back.

We use angular + asp net core.

Somehow the message we get contains square brackets. I think this indicates that the message is also localized.

However, we add those keys in the localization xml files we still don't get the message you get in the screenshot. Any idea on that?

And thanks for the Fluent Validation. I think this would be the way to go. However, the nuget package does not seem to install. I get the following message.

And I assume this would work which project this should be installed? .Core or better in .Application?

Regards,

it-s en-GB.

Thanks I managed to install the nuget package.

Ok I did a bit more investigation on this and I think i found what causing the issue. I guess it is a bug.

What I did is to disable all other languages( including englis-en) but en-GB. As we do not want to use localization. This is causing the message. As soon as I enable english (en) then I get the same error message with you.

Maybe this should be another question but is there any other place we should disable the localization and just make the default en-GB?

Is there any way to apply migration to multiple db context by using Migrator tool? I don't mean for multi tenant applicaiton. In the application we disabled multi tenant but we have another dbcontext that we would like to apply migration through Migrator.

I would appriciate if you could point me right direction or anyone has this issue.

I have seen here Ismail suggested adding another tenant but I don't find this a good way as this requires storing connection string in database.

I tried this but the instance cannot be created with the following error. Not sure how I should register this in Migrator project.

Message	"Can't create component 'Project.Migrator.MultiTenantMigrateExecuter' as it has dependencies to be satisfied.\r\n\r\n'Project.Migrator.MultiTenantMigrateExecuter' is waiting for the following dependencies:\r\n- Service 'Abp.Zero.EntityFrameworkCore.AbpZeroDbMigrator 1[[Project.EntityFrameworkCore.APLBillingDbContext, Project.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.\r\n"	string

I have followed the same pattern and created SecondDBMigrator class as below:

public class SecondDBMigrator : AbpZeroDbMigrator<SecondDBContext>
        {
            public SecondDBMigrator(
                IUnitOfWorkManager unitOfWorkManager,
                IDbPerTenantConnectionStringResolver connectionStringResolver,
                IDbContextResolver dbContextResolver) :
                base(
                    unitOfWorkManager,
                    connectionStringResolver,
                    dbContextResolver)
            {

            }
        }
        ```
        
With this I don't get exexption but when I look at instance of the migrator connection string in debug mode I see the default database connection string registered instead of second database.  
     

Not sure what that would change but yeah it doesn't work either...

I hope you get my point. The database connection still points to default db context connection.

thanks :)

Nope. Still the default connection string points to the default one...

Both AbpZeroDbMigrator instance and TestAbpZeroDbMigrator instance contain the same default database connection string. I assume this shouldn't be the case.

Configuration.ReplaceService<IConnectionStringResolver, MyDbPerTenantConnectionStringResolver>(); line doesn't seem to have any affect. I tried put the line in .EntityFrameworkCode module PreInitialize method and also tried it in Migrator module but still no luck.

In .EntityFrameworkCore there is already Default module one as below

Configuration.ReplaceService<IConnectionStringResolver, DefaultDbConnectionStringResolver>();

here is well _connectionStringResolver always points to default database connection string.

I started doubting that Migrator can be used to apply migration to multiple db context.. ?

Showing 1 to 10 of 54 entries