-
Notifications
You must be signed in to change notification settings - Fork 380
Description
Hello Mapster Team,
I encountered an issue while using Mapster to map a Database object. During the mapping process, the UserId property of the Database object is set to null event though it has a value before the adaptation.
Models Involved:
public sealed record Database(
string Server = "",
string Name = "",
string? UserID = null,
string? Password = null);
public sealed class Company : Entity
{
public string Name { get; set; } = default!;
public string ShortName { get; set; } = default!;
public Database Database { get; set; } = default!;
public Tax Tax { get; set; } = default!;
public Address Address { get; set; } = default!;
public List<Sube>? Subeler { get; set; }
}
public sealed record CompanyUpdateCommand(
string Id,
string Name,
string ShortName,
Database Database,
Tax Tax,
Address Address,
bool IsActive) : IRequest<Result<string>>;
Mapping Code:
Company? company = await companyRepository.Where(p => p.Id == request.Id)
.Include(p => p.Subeler)
.FirstOrDefaultAsync(cancellationToken);
if (company is null)
{
return Result<string>.Failure("Company not found");
}
request.Adapt(company);
company.Database = request.Database;
Issue:
During the mapping process, the request.DatabaseUserID property has a valid value, but after adaptation, the company.Database.UserId property becomes null. Other properties in the Database object are mapped correctly, but this specific property is not.
Expected Behavior:
The request.Database.UseID value should be property mapped to the company.Database.UserID property without turning null.
Steps Taken:
- Verified that the request.Database.UserID property has a value before the mapping.
- Ensured no custom mapping rules interfere with the mapping process.
- Confirmed that the issue only affects the UserID property.
Could this be a bug or is there a specific configuration required for this scenario? I would appreciate your guidance in resolving this issue.
Thank you! 😊