0
Web APIを使用しています。モデルをビューモデルにマップしようとしています。ここAutomapperを使用したWeb APIでは、タイプマップの設定が欠落しているか、サポートされていないマッピングがあります
- DALレイヤ(クラスライブラリプロジェクト)私はオートマッパに
- BLLレイヤーを使用しています(クラス:しかし、私は
Missing type map configuration or unsupported mapping
私は以下の層を持っていることを示すエラーメッセージを取得していますライブラリプロジェクト)
- サービス層(ウェブAPIプロジェクト)
とここに私のコードです:
回の初期クラス:
public class DomainToViewModelMap : AutoMapper.Profile
{
public override string ProfileName
{
get { return "ViewModelToDomainMappings"; }
}
protected override void Configure()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<Notification, NotificationModel>();
});
}
}
public class ViewModelToDomainMap : AutoMapper.Profile
{
public override string ProfileName
{
get { return "ViewModelToDomainMappings"; }
}
protected override void Configure()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<NotificationModel, Notification>();
});
}
}
public class AutoMapperConfigurationTest
{
public static void Configure()
{
Mapper.Initialize(x =>
{
x.AddProfile<DomainToViewModelMap>();
x.AddProfile<ViewModelToDomainMap>();
});
}
}
そして、私はGlobal.asaxの中のApplication_Startからそれを呼び出しています:
protected void Application_Start()
{
AutoMapperConfigurationTest.Configure();
}
DAL層:
public static NotificationModel GetByID(int ID)
{
using (Data.ZajelEntities db = new Data.ZajelEntities())
{
var notification = db.Notifications.Find(ID);
if (notification != null)
{
return Mapper.Map<Notification, NotificationModel>(notification);
}
}
return null;
}
が、私はこの問題に関連していることを知っています私は初期化コードは、Web APIのGlobal.asaxを実行すると確信しています
何が欠けていますか?
ここでエラーが発生しますか? – MacakM
私がモデルからビューモデルにマップするとき、私が上記のように。私は、次のような例外状態を持っています。タイプマップの設定が欠落しているか、サポートされていないマッピング –