Base solution for your next web application
Open Closed

GetXXXForEdit is Filling Some String Fields with Spaces #6399


User avatar
0
mdframe created

ASP.NET Core + Angular v6.5.0

We need some insight. We recently added two fields to an existing database and entity. The database does not have any spaces for these fields stored in their columns however when we perform the GetXXXForEdit function the field immediately has been max filled with the length. The MinLength is set to 0 and Max is 15. Here are the code snippets:

[AbpAuthorize(AppPermissions.Pages_ProductLocations_Edit)]
		 public async Task<GetProductLocationForEditOutput> GetProductLocationForEdit(EntityDto<long> input)
         {
            var productLocation = await _productLocationRepository.FirstOrDefaultAsync(input.Id);  <-- Field Filled with spaces here
           
		    var output = new GetProductLocationForEditOutput {ProductLocation = ObjectMapper.Map<CreateOrEditProductLocationDto>(productLocation)};
	[Table("ProductLocations")]
    public class ProductLocation : FullAuditedEntity<long> , IMustHaveTenant
    ...
    ... Other Entity Fields...    
    ...
        [StringLength(ProductLocationConsts.MaxIMEILength, MinimumLength = ProductLocationConsts.MinIMEILength)]
        public string IMEI { get; set; }       
 public const int MinIMEILength = 0;
 public const int MaxIMEILength = 15;

What are we missing or done incorrectly in this situation?

Thx


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mdframe

    • Is the _productLocationRepository a generic repository ?
    • Are you using SQL Server or any other DB server ?
  • User Avatar
    0
    mdframe created

    Hi @ismcagdas,

    The db is SQL Server and the only connection for this repository is ProductLocation table.

    Thx

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mdframe

    Could you share what is the datatype for your IMEI column in the database ? Is it nvarchar or varchar ?

    Thanks,

  • User Avatar
    0
    mdframe created

    @ismcagdas,

    Sorry about that, here is the column information:

    [IMEI] [nvarchar](15) NOT NULL,
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mdframe

    Could you share your solution via email with us ? to [email protected] ?

    Thanks,