简体   繁体   English

AutoMapper IDataReader将默认值映射到实体

[英]AutoMapper IDataReader Mapping default value to entity

im using AutoMapper for map entity and DataSet 即时通讯使用AutoMapper进行地图实体和DataSet

AutoMapper.Mapper.CreateMap<IDataReader, Home>():

and i have a property call MobileNumber in Home entity and want to map static value for this property in entity so how can i add static value when entity is mapping with DataSet ? 我在Home实体中有一个属性调用MobileNumber,并希望在实体中映射此属性的静态值,那么当实体与DataSet映射时如何添加静态值?

我能找到方法

AutoMapper.Mapper.CreateMap<IDataReader, Booking>().ForMember(d => d.Days, opt => opt.UseValue(2));

You can define a constant value for your MobileNumber property like this: 您可以为MobileNumber属性定义一个常量值,如下所示:

Mapper.CreateMap<IDataReader, Home>().ForMember(dest => dest.MobileNumber,
                                                opt => opt.MapFrom(src => "MyConstantValue"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM