-
Source: public class Story
{
// ...
public DateTime CreationDate { get; set; }
public DateTime? PublicationDate { get; set; }
public IList<Chapter> Chapters { get; set; }
}
public class Chapter
{
// ...
public CommentsThread CommentsThread { get; set; }
}
public class CommentsThread
{
// ...
public int CommentsCount { get; set; }
} Target: public class StoryDetails
{
public DateTime ReleaseDate { get; set; }
public bool IsPublished { get; set; }
public bool CommentsCount { get; set; }
} Mapper: [Mapper]
public static partial class StoryMapper
{
public static partial IQueryable<StoryDetails> ProjectToDetails(this IQueryable<Story> q);
// Does not work
private static int MapCommentsCount(IList<Chapter> chapters)
=> chapters.Sum(c => c.CommentsThread.CommentsCount);
// Neither do those two
private static DateTime MapReleaseDate(Story story) => story.PublicationDate ?? story.CreationDate;
private static bool MapIsPublished(DateTime? publicationDate) => publicationDate != null;
} |
Beta Was this translation helpful? Give feedback.
Answered by
latonz
Jul 9, 2024
Replies: 1 comment 3 replies
-
Is the posted target class exactly as it is in your code? The error message indicates that the members are required, which is not the case in the posted code. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: you need to apply the
MapProperty
to a mapping method with the classes as parameter / return types, not wrapped inIQueryable
. Otherwise Mapperly tries to apply theMapProperty
attribute to theIQueryable
which doesn't have these properties.Mapperly will pick up the configuration from the
Map
method whenever mapping fromStory
toStoryDetails
.See also the documentation.