我有 2 个项目,都使用相同版本的自动映射器。因此,这两个项目都需要使用此代码配置配置文件
public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
//CreateMap goes here
}
}
如您所见,我将从自动映射器继承类Profile
。但是问题发生在另一个项目上。
此项目的命名空间为 Profile.API
。所以发生的情况是我得到了错误'Profile' is a namespace but is used like a type
这是我的类AutoMapperProfile
的完整代码
using AutoMapper;
namespace Profile.API.Infrastructure.AutoMapper
{
public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
//CreateMap goes here
}
}
}
需要建议
为自动映射器using
指定别名:
using AM = AutoMapper;
namespace Profile.API.Infrastructure.AutoMapper
{
public class AutoMapperProfile : AM.Profile
{
public AutoMapperProfile()
{
//CreateMap goes here
}
}
}