2011-10-28 3 views
1

のは、私はこのようなドメインオブジェクトがあるとしましょう:私の見解についてはAutomapper内の未使用の特性を無視しないための波及効果は何ですか?

public class Product 
{ 
    public int Id {get;set;} 
    public string Name {get;set;} 
    public string Description {get;set;} 
    public int DisplayOrder {get;set;} 
    //Lots of other properties 
} 

は、しかし、私は、製品クラスの別のプロパティを使用し2つの異なるビューモデルを使用します。

Automapperについては
public class ProductViewModel1 
{ 
    public int Id {get;set;} 
    public string Name {get;set;} 
    //A mix of some of the other properties 
} 
public class ProductViewModel2 
{ 
    public int Id {get;set;} 
    public string Description {get;set;} 
    //A different mix of the other properties 
} 

Mapper.CreateMap<Product, ProductViewModel1>(); 
Mapper.CreateMap<Product, ProductViewModel2>(); 

質問(複数可): はそれが必要ですが、CreateMapするすべて無視プロパティを追加するには?大規模なオブジェクトでこれが行われないと、大きなオーバーヘッドはありますか?ありがとう。

答えて

1

その必要はありませんが、あなたはあなたのユニットのマッピングをテストする(または、それらが正確であることを確認するために、実行時に主張する)それが成功するために無視が必要な場合。

Mapper.AssertConfigurationIsValid(); 

あなたはAutoMapper構成の検証についての詳細を読むことができますが、ここで正しいです:

http://automapper.codeplex.com/wikipage?title=Configuration%20Validation

+0

おかげでポール。このリンクは、ユニットテストでマップされていないすべてのプロパティを無視するために参照される拡張メソッドのために役立ちました。 – trevorc

関連する問題