Starts in:
2 DAYS
9 HRS
49 MIN
24 SEC
Starts in:
2 D
9 H
49 M
24 S
Open Closed

BUG: abp-suite 6.0.1 Entity generation #3995


User avatar
0
rwright-ruhealth created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: v6.0.1
  • UI type: MVC in VS 2022 with SQL Server 2014
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace: 500 error
  • Steps to reproduce the issue:" create an entity using the ABP-SUITE 6.0.1 from an existing entity using load existing entity.
  • The "wizard" created class is almost correct, however the missing "this" reference for the left hand side of the expression in the class constructor results in a 500 error when viewing the Index page if the field is a required field, because null is not allowed. If null is allowed, you will get a new city record with no city. because the parameter and member variable have the same name from the
  • code generator.
  • Example Code generated by apb-suite before manual fixup: [ please do not count this legitimate bug report against my 30 allotment ]
public City(Guid id, string ci_city = null)
        {

            Id = id;
            Check.Length(ci_city, nameof(ci_city), CityConsts.ci_cityMaxLength, 0);
            ci_city = ci_city;  // THIS SHOULD BE this.ci_city=city;
        }
      
** working code  
// recommendation: USE "this" to disambiguate between local variables and parameters and member variables that happen to have the same identifier name
public City(Guid id, string ci_city = null)
        {

            Id = id;
            Check.Length(ci_city, nameof(ci_city), CityConsts.ci_cityMaxLength, 0);
            this.ci_city = ci_city;  // THIS SHOULD BE this.ci_city=city;
        }

**** recommendation: USE "this" to disambiguate between local variables and parameters and member variables that happen to have the same identifier name.****


5 Answer(s)
  • User Avatar
    0
    rwright-ruhealth created

    recommendation: USE "this" with member variables with the same name to disambiguate between local variables and parameters and member variables that happen to have the same identifier name, which abp-suite generates automatically.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Could you provide the full steps to reproduce? we will check it out and yes we will refund your ticket if it's a problem.

  • User Avatar
    0
    rwright-ruhealth created

    Liangshiwei; Steps to reproduce:

    Create a cities table in a sql server database: script below.

    /****** Object:  Table [dbo].[Cities]    Script Date: 11/4/2022 8:21:55 AM ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE TABLE [dbo].[Cities](
    	[id] [uniqueidentifier] NOT NULL,
    	[ci_city] [nvarchar](50) NULL,
    	[ExtraProperties] [nvarchar](max) NULL,
    	[ConcurrencyStamp] [nvarchar](40) NULL,
    	[CreationTime] [datetime2](7) NOT NULL,
    	[CreatorId] [uniqueidentifier] NULL,
    	[LastModificationTime] [datetime2](7) NULL,
    	[LastModifierId] [uniqueidentifier] NULL,
    	[IsDeleted] [bit] NOT NULL,
    	[DeleterId] [uniqueidentifier] NULL,
    	[DeletionTime] [datetime2](7) NULL,
     CONSTRAINT [PK_Cities] PRIMARY KEY CLUSTERED 
    (
    	[id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    
    ALTER TABLE [dbo].[Cities] ADD  CONSTRAINT [DF_Cities_uid]  DEFAULT (newsequentialid()) FOR [id]
    GO
    
    ALTER TABLE [dbo].[Cities] ADD  CONSTRAINT [DF__Cities__Creation__3DE82FB7]  DEFAULT (getdate()) FOR [CreationTime]
    GO
    
    ALTER TABLE [dbo].[Cities] ADD  CONSTRAINT [DF__Cities__IsDelete__3EDC53F0]  DEFAULT (CONVERT([bit],(0))) FOR [IsDeleted]
    GO
    

    Next, use abp-suite to load the entity from database and select only the ci_city property name. Uncheck all other fields. Choose primary key type of Guid. Set a menu icon of file-alt. Choose : Check the Create user interface; Create backend; Add migration; Uncheck Update database Check Create unit and integration tests. Rename the Name to City; Leave plural name as Cities, Database table/collection name is Cities Change namespace to CitiesNs Set Base Class to FullAuditedEntity and primary key to Guid. Save and Generate the entity. Examine the class generated by the Abp-suite generator in domain project. This is what I consistently get for all project entities created:

    namespace ManytoMany.CitiesNs
    {
        public class City : FullAuditedEntity<Guid>
        {
            [CanBeNull]
            public virtual string ci_city { get; set; }
    
            public City()
            {
    
            }
    
            public City(Guid id, string ci_city = null)
            {
    
                Id = id;
                Check.Length(ci_city, nameof(ci_city), CityConsts.ci_cityMaxLength, 0);
                ci_city = ci_city;
            }
    
        }
    

    Notice there is no** this.ci_city** which causes the ci_city property to remain null when submitted to the database on the create method, because the class property is not assigned to. Instead the parameter property is being set to itself. When I correct the code to use:this.ci_city=ci_city, the data is properly saved on create. As you know, the this.ci_city refers to the class property and without the word this, it refers to the parameter. It is not an issue when the class property has a different case or name than the parameter, because there is no ambiguity. Also, my database fields are all lower case. The class produced by the abp suite is shown below.

    namespace ManytoMany.CitiesNs
    {
        public class City : FullAuditedEntity<Guid>
        {
            [CanBeNull]
            public virtual string ci_city { get; set; }
    
            public City()
            {
    
            }
    
            public City(Guid id, string ci_city = null)
            {
    
                Id = id;
                Check.Length(ci_city, nameof(ci_city), CityConsts.ci_cityMaxLength, 0);
                ci_city = ci_city;
            }
    
        }
    

    Rick Wright Subject: [EXTERNAL] BUG: abp-suite 6.0.1 Entity generation (#3995) Answered by liangshiwei. — Hi, Could you provide the full steps to reproduce? we will check it out and yes we will refund your ticket if it's a problem.


    You are receiving this because you are subscribed to this question. Do not reply to this email. Click here to view #3995 in browser.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Thanks, we will check it.

  • User Avatar
    0
    yekalkan created
    Support Team Fullstack Developer

    @rwright-ruhealth I've refunded your question credit and we will fix this in next release.

    However, using PascalCase for public properties is recommended widely.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06