Strongly Typed Ids #306
Closed
DermotMurphy
started this conversation in
General
Replies: 2 comments
-
The problem is that
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks Lars.
Excellent explanation 👍
…On Thu, 30 Mar 2023, 17:06 Lars, ***@***.***> wrote:
The problem is that nameof only resolves the symbol it references, for
User.Id.Value it is Value but you want to reference the property path
Id.Value.
[MapProperty(nameof(User.Id.Value), nameof(UserDto.Id))]
resolves to
[MapProperty("Value", "Id")]
but what you actually want is
[MapProperty("Id.Value", "Id")] or with nameof [MapProperty(new[] {
nameof(User.Id), nameof(User.Id.Value) }, new[] { nameof(UserDto.Id) })].
—
Reply to this email directly, view it on GitHub
<#306 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACPKZR4CBJPPFRHQ652LLHDW6WVRFANCNFSM6AAAAAAWNO75DA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to map a Domain Entity (User) to a DTO (UserDto) using this mapper:
[Mapper]
public static partial class UserMapper
{
[MapProperty(nameof(User.Id.Value), nameof(UserDto.Id))]
public static partial UserDto MapUserToDto(User user);
}
public class User
{
public UserId Id { get; set; }
public required string FirstName { get; set; }
}
public readonly record struct UserId(Guid Value);
public class UserDto
{
public Guid Id { get; set; }
public string? FirstName { get; set; }
}
Program.cs looks like this:
var user = new User
{
Id = new UserId(Guid.NewGuid()),
FirstName = "James",
LastName = "Kirk"
};
var dto = UserMapper.MapUserToDto(user);
Console.WriteLine(dto);
I am getting two identical errors:
Severity Code Description Project File Line Suppression State
Error RMG006 Specified property Value on source type ConsoleMappingObjects.User was not found ConsoleMappingObjects E:\Source\Repos\ConsoleMappingObjects\ConsoleMappingObjects\UserMapper.cs 8 Active
Does this MappingAttribute do what I believe it ought to?
[MapProperty(nameof(User.Id.Value), nameof(UserDto.Id))]
I am expecting the Value property of the Id property on the User object to be mapper to the Id property on the UserDto object.
Am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions