将实体 iEnumerator 映射到 Dto 枚举器
我正在使用 CQRS。我从数据库中选择我的实体 IEnumerator,我想将其映射到我的 Dto 类。
我的 Dto 类:
public class XCollectionDto
{
public IEnumerable<XReadDto> Entries { get; init; } = Enumerable.Empty<XReadDto>();
}
我的映射器类:
public class XReadMapper : IEntityToDtoMapper<X, XCollectionDto>
{
public XCollectionDto Map(IEnumerable <X> source, XCollectionDto target)
{
//todo
Here i want to map source to target Entries list
}
}
如果没有 for 循环,我该如何做到这一点?我没有使用 AutoMaper,映射是手动的
I am using CQRS. I select my Entities IEnumerator from database and i want to map this to my Dto class.
My Dto class:
public class XCollectionDto
{
public IEnumerable<XReadDto> Entries { get; init; } = Enumerable.Empty<XReadDto>();
}
My mapper class:
public class XReadMapper : IEntityToDtoMapper<X, XCollectionDto>
{
public XCollectionDto Map(IEnumerable <X> source, XCollectionDto target)
{
//todo
Here i want to map source to target Entries list
}
}
How can i do that, without a for loop? I am not using AutoMaper, the mapping is manual
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你可以用C#反射来实现你的目的
我创建了两个类进行测试:
绑定somemodelDTO的属性的方法,这些属性与somemodel的属性同名:
结果:


I think you could accompish your purpose with C# reflection
I created the two class for test:
the method to bind properties of somemodelDTO which have the same name with properties of somemodel:
The result:

