Activities of "christophe.baille"

Issue resolved.

After getting the error, everything is generated (UI, back-end) appart of the migration of the migration file.

To go further, some changes need to be done on our code:

1- *DbContextModelCreatingExtensions.cs file:

From the entity you generated, delete this line:

b.HasOne<AppUser>().WithMany().HasForeignKey(x => x.AppUserId);

2- On EntityGenerated.cs, add:

public AppUser AppUser { get; set; }

3- On AppUser.cs, add:

public EntityGenerated EntityGenerated { get; set; }

4- On OnModelCreating method of *MigrationDbContext.cs, add:

            builder.Entity<EntityGenerated >(b =>
            {
                b.Ignore(x => x.AppUser);
                    b.HasOne<IdentityUser>().WithOne().HasForeignKey<EntityGenerated >(x => x.AppUserId);
            });

NOTE: Be very careful to use Volo.Abp.Identity.IdentityUser for IdentityUser, by using Microsoft.AspNetCore.Identity.IdentityUser it will not work

5- On OnModelCreating method of *DbContext.cs, add:

            builder.Entity<EntityGenerated>(b =>
            {
                    b.HasOne(x => x.AppUser).WithOne(x => x.EntityGenerated).HasForeignKey<EntityGenerated>(x => x.AppUserId);
            });

Once everything is done, you can now generate the migration script and update the database.

Thanks again Liangshiwei for your support

With this, I got this error:

The relationship from 'StaffProfile' to 'IdentityUser' with foreign key properties {'AppUserId' : Nullable<Guid>} cannot target the primary key {'Id' : string} because it is not compatible. Configure a principal key or a set of compatible foreign key properties for this relationship.

So I tested by creating another field for the primary key in my ExistProfile entity:

public string AppUserIdString { get; set; }

It then generate a script but it is not what I want:

  • it create a new column, I want to keep AppUserId as it is in production already, i can not change the type. Plus if I want to change the type, I need to change a lot of code

  • the script create a new table IdentityUser, we are actually using ABPUser table, we can not use another.

I tried your changes but several parts were wrong on the code, I then changed like this:

1- Remove b.HasOne<AppUser>().WithMany().HasForeignKey(x => x.AppUserId); in YourDbContextModelCreatingExtensions. → OK

2- Open *MigrationsDbContext, add the following code in the OnModelCreating method:

b.Ignore(x => x.AppUser); //Replace by AppUserId as AppUser does not exists

builder.Entity<IdentityUser>(b => { b.Property<Guid?>(nameof(AppUser.MyExistingEntityId)); //Replace by Id as MyExistingEntityId does not exists b.HasOne<MyExistingEntity>().WithMany().HasForeignKey(nameof(AppUser.MyExistingEntityId)); //Replace by Id as MyExistingEntityId does not exists });

3- Open *DbContext, add the following code in the OnModelCreating method:

b.Property<Guid?>(nameof(AppUser.OrganizationId)); //Replace by Id as OrganizationId does not exists

b.HasOne<MyExistingEntity>().WithMany().HasForeignKey(nameof(AppUser.MyExistingEntityId)); //Replace by Id as MyExistingEntityId does not exists

builder.ConfigureCustomApplicationModules(); // Commented it as I do not have this method I have this instead, but seems the same: builder.ConfigureMyApp();

I guess all the part builder.Entity<Test> was for test? I did try to add it but I do not know what to put to make it working...

After making this changes I then try to create migration files but I got this error:

The property 'Id' cannot be added to type 'IdentityUser' because the type of the corresponding CLR property or field 'string' does not match the specified type 'Nullable<Guid>'

Please keep me updated, I am available for remote connection, it might be faster to solve this than the way we do actually.

Thanks

Hello maliming,

You are right, I removed all changes mentionned for .net project before and just put changes on the angular part.

So now when I run the angular page, I got the Finnish language and can change perfectly.

I still have the issue that if I go directly to this page https://localhost:44367/Account/Login, I will not have the language I want. I will see if it is part of our requirements. By the way, to make Angular working, I added the changes on Angular code but had to remove all the code suggested in .NET.

by adding this on angular, it is working now.

However, when I go to https://localhost:44367/Account/Login it remain in english, then after login, I go back to Angular in Spanish. If I am right, it is related to this ticket: https://support.abp.io/QA/Questions/1324/How-to-change-language-of-login-page-when-user-changes-language-of-application

Thanks

Is there anyone following this ticket? I am stuck on my migration since about 10 days now and I still have no clue on how or when I will complete it...

Thank you

Yes, I saw while you connected that mvc looks ok. I wait some news from you regarding Angular then, thank for your support

It is what my colleague did before, similar code, he added this into startup.cs but it was not running well.

        app.UseAbpRequestLocalization(options =>
        {
            var acceptLanguageHeaderRequestCultureProvider = options.RequestCultureProviders
                  .OfType&lt;AcceptLanguageHeaderRequestCultureProvider&gt;()
                  .FirstOrDefault();
            if (acceptLanguageHeaderRequestCultureProvider != null)
            {
                options.RequestCultureProviders.Remove(acceptLanguageHeaderRequestCultureProvider);
            }                
        });

I tried adding lines you mentionned on into MyProjectHttpApiHostModule.cs, OnApplicationInitialization method but it behave not correctly, the language selected is fine now (on the menu), but the text is in spanish and can not be changed:

When I open the app from incognito, it will then open in Spanish (Default Language). If I open the app in another browser with English previously saved in cache/cookies for this application, it will open with the English language selected, but the text will be is Spanish. And in both cases, when I try to change the language from the menu, it will remain in Spanish...

I am not sure to understand your explanation about the last line of code, I think the language is already stored on cookies. If I open the app, select the language I want then close the browser, then open again, it will remember it and not take language from the OS or browser setting, so I guess it takes it from the cookie already.

I just tried by adding lines of code you did mention in:

ConfigureServices method from MyProjectApplicationModule.cs

ConfigureLocalization method from MyProjectHttpApiHostModule.cs

ConfigureLocalization method from MyProjectHttpApiModule.cs

ConfigureServices method from MyProjectDomainModule.cs

I changed in all project, just in case. But I did not see any difference on anything about the language management.

What we need, if possible is:

  • when user open the app on his browser, whatever is the language of OS or browser, the first time it will be in Finnish
  • if the user change the language, then the next time he open again, it will be this language (not Finnish)

My colleague did previously and put something similar to your code suggestion in startup.cs, it was taking the default languge at opening, but then we were not able to change the language anymore.

Thanks for your help

Showing 121 to 130 of 148 entries
Made with ❤️ on ABP v9.0.0-preview Updated on September 19, 2024, 10:13