2017-09-21 116 views
1
public class AutoMapperBootstrap : AutoMapper.Profile 
{ 
    protected override void Configure() 
    { 
     //ReplaceMemberName("Z", "A"); 
     //CreateMap<Source, Destination>(); 
    } 
    public override string ProfileName 
    { 
     get { return this.GetType().Name; } 
    } 
} 

我有這個AutoMapperBootstrap類在我的MVC應用程序的文件夾App_Start。覆蓋無效配置()給編譯錯誤「AutoMapperBootstrap.Configure()「:發現沒有覆蓋合適的方法」

中的「配置」的方法是讓編譯器錯誤 - 「沒有合適的方法重寫」,我得到的配置方法,而不是摘要名稱

我已經看到了在StackOverflow上壓倒一切的配置方法的例子很多錯誤自定義Automapper配置文件中的配置文件。

但爲什麼我得到這個編譯器錯誤。

請讓我知道我在做什麼錯誤?

或者它是最新版本的Automapper沒有這個配置方法被覆蓋。

注意:我已將最新的Automapper版本6.1.1.0從Nuget下載到我的應用程序中。

+0

嘗試從'Configure'移動你的代碼,構造 – ASpirin

回答

2

更新版本的AutoMapper have a different method用於設置配置文件。我正在使用這裏描述的方法在.net項目的類庫中設置自動化。

namespace Project.Helpers 
{ 
    public class NewMapperProfile : Profile 
    { 
     public NewMapperProfile() 
     { 
      CreateMap<ClassA, ClassB>(); 
     } 
    } 
} 
+0

所以,我也發現了較新版本的AutoMapper的不使用「覆蓋配置」的方法了。另外,我測試了上面創建配置文件的方法,它可以工作。我希望這有幫助! –