.net 未找到自动映射器-映射器
我似乎无法与AutoMapper合作 首先,文档是错误的或过时的,或者我很愚蠢:.net 未找到自动映射器-映射器,.net,automapper,.net,Automapper,我似乎无法与AutoMapper合作 首先,文档是错误的或过时的,或者我很愚蠢: AutoMapperConfiguration.Configure(); // this doesn't exist 其次,我通过调用以下命令创建地图: Mapper.CreateMap(myType1, myType2) 其中类型实际上是彼此的精确属性映射 但是当我打电话的时候 Mapper.Map(myInstanceOf1, myType2) 我得到一个映射器未找到错误。如果我检查AutoMapper
AutoMapperConfiguration.Configure(); // this doesn't exist
其次,我通过调用以下命令创建地图:
Mapper.CreateMap(myType1, myType2)
其中类型实际上是彼此的精确属性映射
但是当我打电话的时候
Mapper.Map(myInstanceOf1, myType2)
我得到一个映射器未找到错误。如果我检查AutoMapper internal _objectMapperCache字典,我可以看到上面映射的内部值为null,因此出现异常
我做错了什么?尝试使用通用语法,它对我很有用:
Mapper.CreateMap<A, B>().ForMember(....
b = Mapper.Map<A, B>(a);
尝试使用通用语法,它对我很有用:
Mapper.CreateMap<A, B>().ForMember(....
b = Mapper.Map<A, B>(a);
您需要自己创建AutoMapperConfiguration类。添加一个静态配置方法并将配置代码放在那里。例如:
public class AutoMapperConfiguration
{
public static void Configure()
{
Mapper.Initialize( x => x.AddProfile<MyProfile>() );
}
}
public class MyProfile : Profile
{
public override string ProfileName
{
get { return "MyProfile"; }
}
public MyProfile()
{
// Configuration here
CreateMap<Account, AccountViewModel>();
}
}
您需要自己创建AutoMapperConfiguration类。添加一个静态配置方法并将配置代码放在那里。例如:
public class AutoMapperConfiguration
{
public static void Configure()
{
Mapper.Initialize( x => x.AddProfile<MyProfile>() );
}
}
public class MyProfile : Profile
{
public override string ProfileName
{
get { return "MyProfile"; }
}
public MyProfile()
{
// Configuration here
CreateMap<Account, AccountViewModel>();
}
}
我需要使用FormMember吗?我只想映射所有属性。我只是以防万一,但我想你不需要。顺便说一下,我从不调用Configure,因为我没有自定义配置。我需要使用FormMember吗?我只想映射所有属性。我只是以防万一,但我想你不需要。顺便说一下,我从不调用Configure,因为我没有自定义配置。