Open Closed

Extend properties #1494


User avatar
0
Leonardo.Willrich created

Hi,

I've added some properties dynamically in the Tenant form. But, for the boolean fields, if the user don't tick then, when saving the form it says that the field is mandatory. The user has to tick and untick the field to be able to save. It seems that the default value is null, but my property is non-nullable.

Framework: Blazor WASM version 4.3.2


6 Answer(s)
  • User Avatar
    0
    cotur created

    Hi Leonardo.Willrich,

    Thanks for informing the situation. We will check this.

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hello there,

    I wrote the necessary codes to reproduce the problem. But it worked fine for me. You can find the codes I wrote to test below;

    I updated the MyProjectNameEfCoreEntityExtensionMappings class in the MyProjectName.EntityFramework project.

        public static class MyProjectNameEfCoreEntityExtensionMappings
        {
            private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
    
            public static void Configure()
            {
                MyProjectNameGlobalFeatureConfigurator.Configure();
                MyProjectNameModuleExtensionConfigurator.Configure();
    
                OneTimeRunner.Run(() =>
                {
                    ObjectExtensionManager.Instance
                        .MapEfCoreProperty<Tenant, Boolean?>(
                            "IsCheck",
                            (entityBuilder, propertyBuilder) =>
                            {
                                propertyBuilder.HasDefaultValue(null);
                            }
                        );
                });
            }
        }
    

    Note: Maybe this step is not necessary for you. Note: This class can be used to map extra properties to table fields in the database. So don't forget to add migration and update the database.

    Open the MyProjectNameDemoModuleExtensionConfigurator in the MyProjectName.Domain.Shared project, and I changed the contents of the ConfigureExtraProperties method as shown below:

            private static void ConfigureExtraProperties()
            {
                ObjectExtensionManager.Instance.Modules().ConfigureSaas(saas =>
                {
                    saas.ConfigureTenant(tenant =>
                    {
                        tenant.AddOrUpdateProperty<Boolean?>(
                            "IsCheck",
                            options =>
                            {
                                options.DefaultValue = null;
                            }
                        );
                    });
                });
            }
    

    Result

    Please let me know if the solution worked for you :)

  • User Avatar
    0
    Leonardo.Willrich created

    Hi @berkansasmaz,

    Your example use a nullable boolean type (boolean?). In my case, I am using a non-nullable boolean type. See my configuration below:

    Could you please change your code and try with a <bool> field instead?

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    This is a bug, we will fix it. by the way, ticket refunded : )

    For now, can you try the code below;

            tenant.AddOrUpdateProperty<Boolean>(
                            "IsActive",
                        options =>
                            {
                                options.Attributes.Clear();
                            }
                        );
    

    Please let me know if it works in your case.

  • User Avatar
    0
    Leonardo.Willrich created

    Hi berkansasmaz,

    Yes, your workaround worked! Do I need to remove that when the fix is released or I can leave there?

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Actually, it's up to you, but I suggest you remove it. Because team members reading the code may have difficulty understanding why that code is there.

    By the way, you can see the fix made here

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15