2017-11-03 5 views
0

私は2つのエンティティEFクラスRegionとCountryを持っています。AutoMapperを使用してマップを作成する6.1.1

public class Region 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public virtual ICollection<Country> Countries { get; set; } 
} 

public class Country 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public int RegionId { get; set; } // FK 
} 

これらのエンティティを対応するViewModelにマップする必要があります。

public class RegionViewModel 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public virtual ICollection<int> Countries { get; set; } 
} 
public class CountryViewModel 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
} 

ただし、AutoMapper 6.1.1ではMapperにはCreateMapの定義が含まれていません。 Mapper.CreateMap<Regin, RegionViewModel>() どうすれば解決できますか?

答えて

0
var config = new MapperConfiguration(cfg => cfg.CreateMap<RegionViewModel, Region>()); 
var mapper = config.CreateMapper(); 
Region target = mapper.Map<Region>(source as RegionViewModel); 
関連する問題