C#automapper映射条件 [英] C# automapper mapping condition

查看:103
本文介绍了C#automapper映射条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想让社区数量以及社区删除标志是否真实,然后计数将减去。我写了下面的代码,它的返回全部计算。任何建议的文件 -



代码 -



Mapper.CreateMap()

.ForMember(e => e.CommunityCount,ex => ex.MapFrom(s => s.Communities.Count))

.ForSourceMember(e => e.Builder ,ex => ex.Ignore());



类文件 - 品牌数据模型类文件有 -

public virtual ICollection Communities {get;组;社区类文件之间的


有 -

public bool已删除{get; set;}



谢谢。



我的尝试:



i试过但没有得到正确的解决方案

解决方案

这应该对你有用



 .ForMember(e => e.CommunityCount,ex => ex.MapFrom(s => s.Communities.Where(x => x.Deleted == false).Count)) 


i just want to get Communities count as well as if its community delete flag its true then count will be minus. i had wrote below code, its return all count. any suggestion fot that -

Code -

Mapper.CreateMap()
.ForMember(e => e.CommunityCount, ex => ex.MapFrom(s => s.Communities.Count))
.ForSourceMember(e => e.Builder, ex => ex.Ignore());

class file - Brand data model class file have -
public virtual ICollection Communities { get; set; },

in between Community class file have -
"public bool Deleted { get; set; }"

thanks.

What I have tried:

i tried but not getting correct solution

解决方案

This should work for you

.ForMember(e => e.CommunityCount, ex => ex.MapFrom(s => s.Communities.Where(x=> x.Deleted == false).Count))


这篇关于C#automapper映射条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆