-
is there anyway to get more detailed information on why this cant be created? I dont see any obviously problems as I am using it in an identical manner in other projects. ReceiptMapper.cs(16, 5): [RMG008] Could not create mapping from Sirs.InventoryService.DTOs.CreateReceiptDto to Sirs.InventoryService.DomainEntities.Receipt. Consider implementing the mapping manually. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Can you provide the relevant classes and mapper declaration? |
Beta Was this translation helpful? Give feedback.
-
I have added the classes below in case you can spot the issue but I am very interested to know how I can debug these errors or get greater detail for future. Many thanks using SO.Common.BaseAggregates;
using SO.InventoryService.DomainEntities;
using SO.InventoryService.DTOs;
using SO.InventoryService.ValueObjects;
using Riok.Mapperly.Abstractions;
namespace SO.InventoryService.MappingConfig;
[Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName)]
public partial class ReceiptMapper
{
public partial ReceiptDto ReceiptToReceiptDto(Receipt receipt);
public partial List<ReceiptDto> ReceiptsToReceiptsDto(List<Receipt> receipts);
public partial Receipt ReceiptCreateDtoToReceipt(CreateReceiptDto createReceiptDto);
public partial List<Receipt> ReceiptCreateDtosToReceipts(List<CreateReceiptDto> createReceiptDtos);
public partial Weight WeightDtoToWeight(WeightDto weightDto);
public partial Volume VolumeDtoToVolume(VolumeDto volumeDto);
public partial WeightDto WeightToWeightDto(Weight weight);
public partial VolumeDto VolumeToVolumeDto(Volume volume);
public partial CustomFieldDto CustomFieldToCustomFieldDto(CustomField customField);
public partial List<CustomFieldDto> CustomFieldsToCustomFieldDtos(List<CustomField> customFields);
public partial CustomField CustomFieldDtoToCustomField(CustomFieldDto customFieldDto);
public partial List<CustomField> CustomFieldDtosToCustomFields(List<CustomFieldDto> customFieldDtos);
private DataType MapStringToDataType(string value) => DataType.FromString(value);
}
using SO.Common.Base;
namespace SO.Common.BaseAggregates;
public class CustomField : IEntity
{
public Guid Id { get; set; } = Guid.NewGuid();
public required string Name { get; set; }
public required string Value { get; set; }
public DataType Type { get; set; }
public DateTime CreatedDateTime { get; set; } = DateTime.UtcNow;
public DateTime? UpdatedDateTime { get; set; } = DateTime.UtcNow;
}
public class DataType
{
public static readonly DataType String = new DataType("String");
public static readonly DataType Integer = new DataType("Integer");
public static readonly DataType Decimal = new DataType("Decimal");
public static readonly DataType DateTime = new DataType("DateTime");
public static readonly DataType Bool = new DataType("Bool");
public string Value { get; }
public DataType(string value)
{
Value = value;
}
public override string ToString()
{
return Value;
}
public static DataType FromString(string value)
{
return value switch
{
"String" => String,
"Integer" => Integer,
"Decimal" => Decimal,
"DateTime" => DateTime,
"Bool" => Bool,
_ => throw new ArgumentException($"Unknown DataType value: {value}")
};
}
}
using SO.Common.BaseAggregates;
namespace SO.InventoryService.DTOs;
public record CustomFieldDto
{
public string Name { get; set; }
public string Value { get; set; }
public string Type { get; set; }
public DateTime CreatedDateTime { get; set; }
public DateTime? UpdatedDateTime { get; set; }
}
public record CustomFieldInsertDto
{
public string Name { get; set; }
public string Value { get; set; }
public DataType Type { get; set; }
}
using MongoDB.Bson.Serialization.Attributes;
using SO.Common.Base;
using SO.Common.BaseAggregates;
using SO.InventoryService.Events;
using SO.InventoryService.ValueObjects;
namespace SO.InventoryService.DomainEntities;
[BsonIgnoreExtraElements]
public class Receipt : AggregateRoot
{
private Receipt(int receiptNumber, DateTime? receivedDate,
List<CustomField> customFields, List<ReceiptLine> receiptLines)
{
Id = Guid.NewGuid();
ReceiptNumber = receiptNumber;
ReceivedDate = receivedDate;
CustomFields = customFields;
ReceiptLines = receiptLines;
}
public static Receipt Create(int receiptNumber, DateTime? receivedDate, List<CustomField> customFields,
List<ReceiptLine> receiptLines)
{
var receipt = new Receipt(receiptNumber, receivedDate, customFields, receiptLines)
{
CreatedDateTime = DateTime.UtcNow,
UpdatedDateTime = DateTime.UtcNow
};
receipt.SetState(ReceiptState.Received);
receipt.AddEvent(new ReceiptCreated(receipt));
return receipt;
}
public Receipt Update(Guid id, DateTime? receivedDate)
{
Id = id;
ReceivedDate = receivedDate;
UpdatedDateTime = DateTime.UtcNow;
AddEvent(new ReceiptUpdated(this));
return this;
}
private void SetState(ReceiptState state)
{
State = state;
}
public void Cancel()
{
CancelledDate = DateTime.UtcNow;
UpdatedDateTime = DateTime.UtcNow;
SetState(ReceiptState.Cancelled);
AddEvent(new ReceiptCancelled(this));
}
public int ReceiptNumber { get; private set; }
public DateTime? ReceivedDate { get; private set; }
public DateTime? CancelledDate { get; private set; }
public bool IsCancelled => CancelledDate.HasValue;
// public decimal? TotalWeight => ReceiptLines.Sum(receiptLine => receiptLine.Weight?.Value ?? 0);
//
// public decimal? TotalVolume => ReceiptLines.Sum(receiptLine => receiptLine.Volume?.Value ?? 0);
public List<CustomField>? CustomFields { get; set; }
public List<ReceiptLine>? ReceiptLines { get; set; }
public ReceiptState State { get; private set; } = ReceiptState.Received;
public string StateName => State.ToString();
public enum ReceiptState
{
Received = 1,
Cancelled = 100
}
}
public class ReceiptLine : IEntity
{
public Guid Id { get; set; }
public int LineNo { get; set; }
public string ProductCode { get; set; }
public Guid ReceiptId { get; set; }
public decimal QuantityReceived { get; set; }
public decimal? QuantityExpected { get; set; }
public string? QuantityOfMeasure { get; set; }
public Weight? Weight { get; set; }
public Volume? Volume { get; set; }
public List<CustomField>? CustomFields { get; set; }
public DateTime CreatedDateTime { get; set; }
public DateTime? UpdatedDateTime { get; set; }
}
using SO.InventoryService.DomainEntities;
using SO.InventoryService.ValueObjects;
namespace SO.InventoryService.DTOs;
public record ReceiptDto(
Guid Id,
int ReceiptNumber,
DateTime? ReceivedDate,
// decimal TotalWeight,
// decimal TotalVolume,
Receipt.ReceiptState State,
string StateName,
List<ReceiptLineDto>? ReceiptLines,
List<CustomFieldDto>? CustomFields,
DateTime CreatedDateTime,
DateTime? UpdatedDateTime
);
public record ReceiptLineDto
{
public Guid Id { get; init; }
public int LineNo { get; init; }
public string ProductCode { get; init; }
public Guid ReceiptId { get; init; }
public decimal QuantityReceived { get; init; }
public decimal? QuantityExpected { get; init; }
public string? UnitOfMeasure { get; init; }
public List<CustomFieldInsertDto>? CustomFields { get; init; }
public WeightDto? Weight { get; init; }
public VolumeDto? Volume { get; init; }
public DateTime CreatedDateTime { get; init; }
public DateTime? UpdatedDateTime { get; init; }
};
public record WeightDto
{
public decimal Value { get; set; }
public string Type { get; set; }
}
public record VolumeDto
{
public decimal Value { get; set; }
public string Type { get; set; }
}
public record CreateReceiptDto
{
public int ReceiptNumber { get; set; }
public DateTime? ReceivedDate { get; set; }
public List<CustomFieldInsertDto>? CustomFields { get; set; }
public List<ReceiptLineDto>? ReceiptLines { get; set; }
}
public record UpdateReceiptDto(
Guid Id,
int ReceiptNumber,
DateTime? ReceivedDate,
List<CustomFieldInsertDto>? CustomFields,
List<ReceiptLineDto> ReceiptLines);
using SO.Common.Base;
namespace SO.InventoryService.ValueObjects;
public sealed class Volume : ValueObject
{
public Volume(decimal value, VolumeType type)
{
Value = value;
Type = type;
}
public decimal Value { get; }
public VolumeType Type { get; }
protected override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
yield return Type;
}
public string VolumeUnit => Type.ToString();
}
public enum VolumeType
{
M3 =0,
F3 =1
}
using Sirs.Common.Base;
namespace Sirs.InventoryService.ValueObjects;
public sealed class Weight : ValueObject
{
public Weight(decimal value, WeightType type)
{
Value = value;
Type = type;
}
public decimal Value { get; private set; }
public WeightType Type { get; private set; }
public void SetWeight(decimal value, WeightType type)
{
Value = value;
Type = type;
}
public string WeightUnit => Type.ToString();
protected override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
yield return Type;
}
}
public enum WeightType
{
Kg =0,
Lb =1
} |
Beta Was this translation helpful? Give feedback.
The problem is that
Receipt
does not have an accessible constructor. I'll see why there is no more precise diagnostic.