Base solution for your next web application
Open Closed

Changing size of database column #5701


User avatar
0
statuscast created

Hi,

In Abp we can change the default length of the AbpSettings column by adding this line of code to the EntityFramework.Core\EntityFrameworkCore\CompanyNameDbContext.cs:

 protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
      base.OnModelCreating(modelBuilder);

     //Increase your Setting Value to 4000 chars (translates to NVARCHAR(MAX) 
     modelBuilder.Entity<Abp.Configuration.Setting>().Property(u => u.Value).HasColumnType("nvarchar(max)");

However, in AZ this line of code seems to have no effect. The DB is still being created with column width of 2000. Does this code have to sit in a dfferent project in AspNetZero? We put this line of code in, rebuilt, blew away the database, then run Update-Databse to ensure it was not working.


15 Answer(s)
  • User Avatar
    0
    ryancyq created
    Support Team

    you can try using HasMaxLength instead of HasColumnType.

    See EfCore#MaxLength

  • User Avatar
    0
    statuscast created

    How does that get me varchar(max)?

    I need this to not have a fixed length. Was doing it successfully in Abp.

    why does this work in Abp but not AZ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    If you want to use nvarchar(max), just use string field with no lenght attribute https://docs.microsoft.com/en-us/ef/core/modeling/max-length#conventions

    By the way, this is totally related to EF/EF Core.

  • User Avatar
    0
    statuscast created

    ok so first of all, as I mentioned and the code above shows, I am trying to override the ABP Settings.Value property length so I dont have the ability to just 'set it as a string'.

    I posted this problem to ABP a while ago and the solution they suggested, which works, is the above code I posted.

    It does not work in ASPNETZERO however.

    Simply pointing me to basic Microsoft EF documentation without taking the time to read my problem and then closing this question is not helpful.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Could you share the issue link on ABP ?

    Thanks.

  • User Avatar
    0
    statuscast created

    Hi there,

    Since it wasn't a bug, just a question, I originally posted it in StackExchange, per their request:

    https://stackoverflow.com/questions/51390090/extend-size-of-settings-value-beyond-2-000-characters

    It's very odd because I see the code being hit when I debug, but its completely ignored or overwritten by something in AspNetZero. It works perfectly in my ABP sample project.

  • User Avatar
    0
    statuscast created

    Hi there,

    Any update on this? Not being able to modify the settings table in AZ is concerning, especially since it seems somehow code in my OnModelCreating is being ignored or overwritten. We are at the beginning of a large project where I'm sure other things in this section are going to be required.

    Also, why is work properly in AspNetBoilderPlate but not AspNetZero is still confusing.

  • User Avatar
    0
    ryancyq created
    Support Team

    does this happen only to Abp.Configuration.Setting?

    what about other ABP tables?

  • User Avatar
    0
    statuscast created

    No, it doesn't.

    Guys -- all you have to do is add this one line of code to EntityFrameworkCore\StatusCastDbContext.cs in OnModelCreating:

    protected override void OnModelCreating(ModelBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);
             
                //Increase your Setting Value 
                modelBuilder.Entity<Abp.Configuration.Setting>().Property(u => u.Value).HasColumnType("nvarchar(max)");
                modelBuilder.Entity<Abp.Application.Editions.Edition>().Property(u => u.DisplayName).HasColumnType(("nvarchar(max)"));
                
    

    Can you please just give it a try and see why it isn't working rather than randomly closing this issue on me, or telling me to fix it in ways that aren't even possible. I really need some resolution on this as your column sizes for the Settings table is artificially way too small. As I've pointed out, this works perfectly in AspNetZero.

    Here's a video of what I'm doing from downloading the template from my account to making the change: https://drive.google.com/file/d/1S4yNKa3oLAxUiEzX_4S9ln5mBeQ7z2DB/view?usp=sharing

    thank you.

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi @statuscast, I tried both module-zero-core-template and aspnetzero. I was able to reproduce the missing migrations.

    However, i do notice that even if the migrations up()/down() does not contain migration changes, the modelsnapshot is updated with

      b.Property<string>("Value")
    +         .HasColumnType("nvarchar(max)")
              .HasMaxLength(2000);
    

    Can you try using the following command for creating migrations?

    1. discard .HasColumnType("nvarchar(max)" changes in your snapshot
    2. run dotnet ef migrations add -c MyCompanyDbContext "<migration_name>"

    One difference between the two projects should be identity server configuration aspnetzero and not ``module-zero-core-template`

  • User Avatar
    0
    statuscast created

    This does not work either. Did you try this or just ask me to try it?

    AspNetZero is doing something somewhere that prevents a the basic override. If this didn't work in AspNetBoilerPlate I would think this was architecturally buried somehwere that AZ couldn't control. But this is definitely an AZ issue. Can we get it moved in to the Git issues if no one has a way to resolve?

    It's severly limiting -- the only work around is to build our own separate repository for 1 configuration value.

  • User Avatar
    0
    statuscast created

    This does not work either. Did you try this or just ask me to try it?

    AspNetZero is doing something somewhere that prevents a the basic override. If this didn't work in AspNetBoilerPlate I would think this was architecturally buried somehwere that AZ couldn't control. But this is definitely an AZ issue. Can we get it moved in to the Git issues if no one has a way to resolve?

    It's severly limiting -- the only work around is to build our own separate repository for 1 configuration value.

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, @statuscast i did download a fresh copy of aspnetboilerplate and anz and tested locally (with dotnet cli). As mentioned, i was able to re-produce the missing migrations and was resolved using the suggestion i gave earlier.

    Were you using package console or dotnet cli to create ef migrations?

  • User Avatar
    0
    alper created
    Support Team

    @statuscast are you still having problem on this issue?

  • User Avatar
    0
    ismcagdas created
    Support Team

    It is fixed via email support. Here is the code that worked;