Asp.net 在存储库类库中使用AutoMapper
我想第一次使用AutoMapperAsp.net 在存储库类库中使用AutoMapper,asp.net,.net,repository,automapper,Asp.net,.net,Repository,Automapper,我想第一次使用AutoMapper public static class AutoMapperWebConfig { public static void Configure() { Mapper.Initialize(config => { config.AddProfile(new WebConfigurationProfile()); }); } } public class
public static class AutoMapperWebConfig
{
public static void Configure()
{
Mapper.Initialize(config =>
{
config.AddProfile(new WebConfigurationProfile());
});
}
}
public class WebConfigurationProfile : Profile
{
public WebConfigurationProfile()
{
this.CreateMap<PovUsers, PovUserView>()
.ForMember(x => x.Name, m => m.MapFrom(p => p.PovUserName))
.ForMember(x => x.User, m => m.MapFrom(p => p.PovUserId));
}
}
公共静态类AutoMapperWebConfig
{
公共静态void Configure()
{
初始化(配置=>
{
config.AddProfile(新的WebConfigurationProfile());
});
}
}
公共类WebConfiguration配置文件:配置文件
{
公共网络配置配置文件()
{
这个
.ForMember(x=>x.Name,m=>m.MapFrom(p=>p.PovUserName))
.ForMember(x=>x.User,m=>m.MapFrom(p=>p.PovUserId));
}
}
我有几个项目需要解决。一个Web项目和一个类库(存储库),用于EntityFramework DB上下文。AutoMapper正在Global.asax中初始化
是否有在存储库中使用此映射器的方法。现在,当我尝试执行此操作时,出现一个错误(缺少贴图):
public IQueryable<PovUserView> GetSet() {
return this.dbSet.ProjectTo<PovUserView>(); ;
}
public IQueryable GetSet(){
将此.dbSet.ProjectTo()返回;
}
感谢您的帮助…将您的映射配置和概要文件放在存储库项目的类中,如下所示:
public class AutoMapperConfiguration
{
public static void Configure()
{
Mapper.Initialize(cfg =>
{
cfg.AddProfile<GeneralMapping>();
cfg.AddProfile<CustomerMapping>();
});
}
}
公共类自动映射器配置
{
公共静态void Configure()
{
Mapper.Initialize(cfg=>
{
AddProfile();
AddProfile();
});
}
}
并从要使用存储库的任何web应用程序的Global.asax调用static Configure方法。将映射配置和概要文件放入存储库项目的类中,如下所示:
public class AutoMapperConfiguration
{
public static void Configure()
{
Mapper.Initialize(cfg =>
{
cfg.AddProfile<GeneralMapping>();
cfg.AddProfile<CustomerMapping>();
});
}
}
公共类自动映射器配置
{
公共静态void Configure()
{
Mapper.Initialize(cfg=>
{
AddProfile();
AddProfile();
});
}
}
并从要使用存储库的任何web应用程序的Global.asax调用静态配置方法。Awesome。这就解决了我的问题。。非常感谢你!令人惊叹的。这就解决了我的问题。。非常感谢你!