第一次使用AutoMapper,我很难搞清楚如何使用它.我正在尝试将ViewModel映射到我的数据库表.
我的ViewModel看起来像这样......
public class AddressEditViewModel
{
public AddressEdit GetOneAddressByDistrictGuid { get; private set; }
public IEnumerable<ZipCodeFind> GetZipCodes { get; private set; }
public AddressEditViewModel(AddressEdit editAddress, IEnumerable<ZipCodeFind> Zips)
{
this.GetOneAddressByDistrictGuid = editAddress;
this.GetZipCodes = Zips;
}
}
Run Code Online (Sandbox Code Playgroud)
我试图使用的映射是......
CreateMap<Address, AddressEditViewModel>();
Run Code Online (Sandbox Code Playgroud)
当我运行这个测试时......
public void Should_map_dtos()
{
AutoMapperConfiguration.Configure();
Mapper.AssertConfigurationIsValid();
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误......
AutoMapper.AutoMapperConfigurationException:未映射JCIMS_MVC2.DomainModel.ViewModels.AddressEditViewModel上的以下2个属性:GetOneAddressByDistrictGuid GetZipCodes在JCIMS_MVC2.DomainModel.Address上添加自定义映射表达式,忽略或重命名该属性.
我不确定我应该如何映射这两个属性.我会很感激任何方向.谢谢
标记
场景:包含 100 多个字段的表(不是我做的……我继承了这个) 网站上只需要显示 50 个这些字段 他们希望保留其他 50 个字段以用于历史目的。某些不需要的字段有可能在将来的某个时候成为必需的。
问题:我正在寻找一种方法来轻松识别 50 个必填字段,以便我可以通过查询提取字段名称。
Psuedo Query: Select FieldNames from TableName where Required = Yes
Is there a setting I could change?
What about using Extended Properties?
Run Code Online (Sandbox Code Playgroud)
预先感谢您提供的任何方向。